2012-11-04 35 views
0

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

這裏是我的故事板設置的圖像:

enter image description here

回答

0

看來你有控制器的一個很奇怪的安排。特別是你有兩個導航控制器。

我建議廣告安排一個導航控制器與主控制器作爲根。當您從主控制器轉到詳細控制器時,您可以在相同的導航控制器中執行此操作。 希望這有助於。

0

popViewController是使用詳細視圖和導航控制器時的正確調用。如果這不起作用,那麼因爲您已成功使用導航控制器進行推送,所以出現了錯誤。

基本上,你必須能夠到達你用來推動的相同的導航控制器,當做一個流行。您甚至可以考慮在該詳細信息視圖上設置自定義導航控制器屬性,並在執行推送操作時對其進行分配 - 然後使用它來彈出。

+0

_基本上你必須能夠到達你用來推動的同一個導航控制器,當做一個pop_聽起來像是這個問題。但我怎樣才能參考正確的導航控制器?代碼示例將不勝感激。 – cmac

+0

我在答案中概述了它 - 在詳細視圖中設置UINavigationController屬性,並在執行pushViewController之前對其進行設置。在詳細視圖中,使用該屬性來彈出視圖控制器而不是self.navigationController。 –

相關問題