簡體   English   中英

iPhone:替換RootViewController后,pushViewController不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM