5

我有一個關於AppDelegate中的Navigationcontroller的問題。我使用的是故事板,它看起來像這樣:如何通過使用故事板在AppDelegate中使用自定義的Navigationcontroller

Storyboard

由於使用推送通知的結果,我已經得到了以下的功能在我的AppDelegate文件:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
//... 
} 

當通知到達我想初始化「詳細視圖」 - 需要ID作爲參數的控制器。此ID是我的有效負載的一部分,因此它存在於didReceiveRemoteNotification中。

我想向follwing:

DetailView *detail = [storyboard instantiateViewControllerWithIdentifier:@"detail"]; 

detail.conversationID = theID; 

[self.navigationController pushViewController:detail animated:YES]; 

我在這一點上的問題是:我怎樣才能得到導航控制器?我搜索了一個像「getNavigationControllerByIdentifier」或類似的東西,但沒有找到任何東西。我無法直接實例化Detail View Controller,因爲導航欄在那裏沒有。

我希望你明白我的意思 - 如果你認爲我的做法是完全地錯誤請指正; O)

又一個小信息:這不是重要的我,在詳細的返回按鈕視圖控制器去回到表格視圖 - 當它通過按鈕「載入表格視圖」鏈接到控制器時就足夠了。

謝謝你的幫忙!

回答

8

UINavigationControllerUIViewController子類,也可以在故事板中分配一個標識符。

使用-instantiateViewControllerWithIdentifier:創建UINavigationController並且它是根視圖控制器。您可能需要在代碼中實例化所有中間控制器,然後修改導航控制器的屬性viewControllers以設置適當的導航堆棧。通過這種方式,當應用程序啓動到詳細信息視圖中時,他們可以找回他們的方式,就好像他們已經通過界面手動推送一樣。

+0

謝謝。現在它很清楚並且可以工作:-)(賞金在10個小時內纔可用,所以不用擔心;)) – 2012-01-11 08:23:07

4

您可以在窗口對象上使用rootViewController

UIViewController *rootViewController = self.window.rootViewController; 
// You now have in rootViewController the view with your "Hello world" label and go button. 

// Get the navigation controller of this view controller with: 
UINavigationController *navigationController = rootViewController.navigationController; 

// You can now use it to push your next view controller: 
DetailViewController *detail = [navigationController.storyboard instantiateViewControllerWithIdentifier:@"detail"]; 
detail.conversationID = theID; 
[navigationController pushViewController:detailViewController animated:YES]; 
相關問題