1.在用代码实现navigationController时,一般是在函数 appdelegate文件中的applicationDidFinishLaunching:方法中构建导航控制器,在这里创建控制器并为其指定跟控制
例如
-(void) applicationDidFinishLaunching:(UIApplication *)application {
UIWindows *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[LoginController alloc] init]];
[window addSubview :nav.view]; 这里不要写成控制器的视图
[window makeKeyAndVisible];
}
2.还有就是navigationController上的添加按钮:
self.navigationItem.rightBarButtonItem = [ [ [UIBarButtonItem alloc] initWithTitle:@"Action" style:UIBarButtonItemStylePlain
target:self action:@selector(performAction:) autorelease];
这条语句向导航栏右侧添加一个按钮。当点击按钮时执行performAction函数。
3.向导航控制器推入控制器和推出控制器
推入控制器只要执行 [self.navigationController pushViewController:aController Animated:YES];
推出控制器只要执行 [self.navigationController popViewControllerAnimated:YES];
4