[英]iPhone: pushViewController doesn't work after replacing RootViewController
我希望在當前的RootViewController之前放置一個屏幕。 到目前為止,我對MyAppDelegate
進行了以下修改:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//with this in the existing RootViewController loads correctly
//self.window.rootViewController = self.navigationController;
self.window.rootViewController = [[[HomePageController alloc] init] autorelease];
}
我不完全確定self.navigationController實際如何設置為RootViewController。 無論哪種方式,如果我進行修改,我的HomePageController
都不會正確加載,但是我無法在其之上推送另一個視圖。 我在HomePageController
上有一個簡單的按鈕,它可以執行以下操作(請注意, HomePageController
應該加載當前命名的RootViewController
,而HomePageController
是我想坐在其上方的視圖):
RootViewController *rvC = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]] autorelease];
[self.navigationController pushViewController:rvC animated:YES];
當這段代碼運行時,什么都沒有發生……我不確定為什么,可能與NavigationController有關? 也許我沒有正確或以最佳方式將HomePageController
放在RootViewController
上方?
您當前沒有安裝navgiationController。 要修復您必須更換
self.window.rootViewController = [[[HomePageController alloc] init] autorelease];
與
self.window.rootViewController = [[[UINavigatoinController alloc] initWithRootViewController:[[[HomePageController alloc] init] autorelease]] autorelease];
現在您已經安裝了navigationController並遵循
[self.navigationController pushViewController:rvC animated:YES];
會做正確的工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.