我已经使用故事板构建了主/明细表(下面的摘要设置图像)。导航控制器做得很差,但不幸的是我现在已经走得太远了,无法回头。如果相关,我正在iOS 6中运行。iOS:当通过单击表格单元查看详细信息时,无法从UITableView详细视图导航回主视图
我的问题是,当通过我的主视图(它通过segue代码工作)上的'添加'按钮从主视图导航到详细信息视图时,'完成'按钮代码成功地将我带回主视图。但是,如果通过单击单元格(通过didSelectRowAtIndexPath)导航到详细信息视图,单击“完成”会将我推回到实例化并推动故事板的视图。
didSelectRowAtIndexPath方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailsViewController *detailView = [self.storyboard instantiateViewControllerWithIdentifier:@"AddDetails"];
[self.navigationController pushViewController:detailView animated:YES];
}
我试图尽我所能想出返回到主表视图,但没有我尝试工作。我曾尝试:
[self.navigationController popViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
和
MasterViewController *masterView = [self.storyboard instantiateViewControllerWithIdentifier:@"masterView"];
[self.navigationController pushViewController:masterView animated:YES];
这里是我的故事板设置的图像:
_基本上你必须能够到达你用来推动的同一个导航控制器,当做一个pop_听起来像是这个问题。但我怎样才能参考正确的导航控制器?代码示例将不胜感激。 – cmac
我在答案中概述了它 - 在详细视图中设置UINavigationController属性,并在执行pushViewController之前对其进行设置。在详细视图中,使用该属性来弹出视图控制器而不是self.navigationController。 –