Ios 使用if语句在navigationController中推送tableViewController

Ios 使用if语句在navigationController中推送tableViewController,ios,uitableview,uinavigationcontroller,pushviewcontroller,Ios,Uitableview,Uinavigationcontroller,Pushviewcontroller,以下是ProfilTableViewController.m的表视图委托中If语句的例外: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *currentCell =(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; // Navigation l

以下是ProfilTableViewController.m的表视图委托中If语句的例外:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
UITableViewCell *currentCell =(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
// Navigation logic may go here. Create and push another view controller.
if (currentCell.textLabel.text==@"phrase") {
    MainViewController *phraseViewController =[[MainViewController alloc] initWithNibName:@"mesPhrase" bundle:nil];
    [self.navigationController pushViewController:phraseViewController animated:YES];
}
在故事板上,我创建了一个从ProfilTVC单元到MainViewController的推送,并将TableViewController更改为“MainViewController”

当我运行应用程序时,单击ProfilViewController中的单元格不会执行任何操作:/ wtf

干杯,
Louis

比较字符串的地址,而不是内容。查看
isEqualToString:
方法。

现在您所要做的就是使用prepareFor segue,如下所示:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:@"yourIdentifier"]) {


   DestinationController *destination = [segue destinationViewController];

    // get the selected index
    NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
    //now you can add informations you want to send to the new controller
    //example:
    destination.selectedItem=[myArray objectAtIndex:selectedIndex];

 }

}

别忘了更改segue标识符:选择两个控制器之间的连接,并在右侧的属性检查器中设置它,它必须等于youIdentifier

为什么不使用prepareForSegue?据我所知(和理解),prepareForSegue旨在将信息传递给新视图。但是,我使用了一个从a单元格到新tableviewcontroller的序列。我用故事板设置了它。我做对了吗?我实际上是从一个基于选项卡栏的项目开始的,而且效果很好。最后一次没什么帮助,我想我错过了一件大事。谢谢你的帮助!好的,我更改了代码,尽管它仍然不能推送视图!在
if
try
NSLog(@“%@push%@”、self.navigationController、phraseViewController)中并查看它的内容。它显示:2012-05-31 18:57:30.351 protov03[5300:fb03](null)正在推送,因此它似乎不会推送新的viewcontroller…因此(null)就是说无论是什么
self
都没有为其设置导航控制器。虽然我看了很多Tuto等,但我不知道如何设置导航控制器。nslog仍然显示“(null)push Main ViewController”