我已經使用故事板構建了主/明細表(下面的摘要設置圖像)。導航控制器做得很差,但不幸的是我現在已經走得太遠了,無法回頭。如果相關,我正在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。 –