我從一個類C類執行一些數據加載任務,一旦加載完成,我只想顯示在故事板中準備的Viewcontroller子類。從非UI類顯示ViewController
所以,當一切都很好,下面的方法被稱爲:
- (void)loadingNextView
{
CABBndGSite *mySite = [CABBndGSite alloc];
CABBndGSelectLanguageViewController *vc = [[mySite myRootViewController].storyboard instantiateViewControllerWithIdentifier:@"SelectLanguageViewController"];
[[mySite myRootViewController] presentViewController:vc animated:YES completion:nil];
}
所以我覈實,myRootViewController不爲零。這是一個UINavigationController類。 vc不是零,所以它在故事板中找到了我的視圖。 無論如何,presentViewcontroller消息似乎在做什麼預期。
當然是一個愚蠢的錯誤,但我可憐的iOS編程知識讓我在霧中!
我使用此代碼從ViewController子類成功,因爲我在這裏得到一個有效的ViewController指針,我不明白爲什麼它不起作用。
我也嘗試實現這裏解釋的AppDelegate方法How to launch a ViewController from a Non ViewController class?但我得到一個零導航指針。也許在我的應用程序中連接不好 我可以有一些解釋嗎?
親切的問候,
您沒有初始化'mySite'。 – Kevin 2014-08-30 17:14:49
凱文絕對正確:你需要分配_and_init。 – nzeltzer 2014-08-30 17:27:13
不確定它真的需要,mySite指向已經初始化的單例,並且我在這裏得到正確的指針。 – 2ndGAB 2014-08-31 07:35:28