如果您的視圖已經按照您的預期工作,那麼在模態視圖中添加導航控制器非常簡單。
NewViewController *newView = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
UINavigationController *navView = [[UINavigationController alloc] initWithrootViewController:newView];
[self presentModalViewController:navView animated:YES];
您的模態視圖將繼承導航欄和所有屬性以呈現該模態內的更多視圖。當你完成模態時,只需解除它。
加載導航控制器頂部的更多視圖非常簡單。
AnotherViewController *anotherView = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
[self.navigationController pushViewController:anotherView animated:YES];
手動彈出從堆棧視圖控制器:
// note, you won't need to call this for the auto created back button, that is handled for you
// this would only be if you wanted manual control over going back outside the back button
[self.navigationController popViewControllerAnimated:YES];
一旦你所有的模態視圖完成後,你可以調用這個從任何地方砸淡出人們的視線,並返回到你原來的看法。手持多個細節屏幕,註冊過程等
[self.navigationController dismissModalViewControllerAnimated:YES];
你好比爾,所以,說我有一個按鈕,按下後,帶來了我想用內部的導航控制器的視圖。這段代碼是否會出現在某人按下該按鈕時觸發的方法中?另外,這是否意味着我想使用導航控制器的視圖有自己的整個.xib文件,除了我的應用程序的默認視圖控制器的預先存在的默認.xib文件? – Joseph
是的,這段代碼會進入按鈕按下的方法。導航控制器不需要單獨的.xib。您認爲您將要加載的視圖會進入導航控制器,因此您的視圖會向下移動以騰出空間供導航欄使用。這種方法應該如何工作,你需要它。根據我的代碼加載它,看看它是什麼樣子。我會更新我的答案,向您展示如何將其他視圖推送到堆棧。 –
感謝您的編輯!我有它的工作。這很棒。我做的略有不同,因爲它並不像另一個控制器* anotherView = [[AnotherViewController alloc] initWithNibName:@「AnotherViewController」bundle:nil];',我聲明'AnotherView'爲IBOutlet並通過界面生成器。但除此之外,代碼運行良好,我推入導航堆棧的視圖會像您所說的那樣繼承頂層欄。我留下的唯一問題是如何讓後退按鈕說「返回」而不是前一個視圖的標題? – Joseph