![](/img/trans.png)
[英]Multi view controller and segue navigation error message I don't understand
[英]don't understand how to use navigation controller in iphone
我對iphone非常陌生,我有以下誤解。
在互聯網上有關如何以編程方式使用NavigationController
的教程,它說:
NavigationController must be declared in applicationDidFinishLaunching and must be init with a root.After that you can add views to it.
我有這個:一個UIViewController
類含義( AdiViewController.h, AdiViewController.m and AdiViewController.xib)
,沒有Delegate file
意味着沒有applicationDidFinishLaunching
方法。
我想要做的是從我的AdiViewController
按下按鈕轉到另一個視圖。 我知道我需要一個NavigationController
,它應該保留我的視圖,擁有根AdiViewController
。
但我的問題是我應該在viewDidAppear
初始化那個NavigationController
?...因為我沒有Delegate
文件。
如果你可以用我的這個小問題提供一個最小的例子,那就太棒了。我敢肯定,對於那些高級人員來說這是什么,但我仍然沒有得到它。謝謝
必須在applicationDidFinishLaunching中聲明NavigationController - >這不是真的。 在您的AdiViewController中,如果您按下該按鈕時有按鈕,您想要加載導航控制器嗎?
// Hook this IBAction to your button in AdiViewController
- (IBAction)pushNavController
{
AnotherViewController* rootView = [[AnotherViewController alloc] initWithNibName:@"Anotherview" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:rootView];
[rootView release];
[self presentModalViewController:navController animated:YES];
[navController release];
}
如果你在AnotherViewController中,即你在導航控制器的根視圖控制器中。 您需要從那里推送和彈出視圖控制器。 例如,如果您在AnotherViewController中有一個按鈕:
// push next view controller onto navigation controller's stack
- (IBAction)pushNextViewController
{
NextViewController* nextView = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
// Similarly if you want to go back to AnotherViewController from NextViewController you just pop that from navigation controller's stack
- (IBAction)pushNextViewController
{
[self.navigationController popViewControllerAnimated:YES];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.