标签:
1.效果如下:
2.UINavigationController,导航控制器也是UIViewController的子类
(1)在Appdelegate.h中 设置UIWindow及其根控制器为导航控制器,代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; oneViewController *oneVC = [[oneViewController alloc] init]; oneVC.view.backgroundColor =[UIColor grayColor];
// 设置导航控制器的根控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:oneVC]; // 设置window为可见 [window makeKeyAndVisible]; // 将AppDelegate的window属性设置为自定义的window self.window = window; // 设置窗口的根控制器为导航控制器 window.rootViewController = nav; return YES; }
(2)在导航控制器的根controller中设置如下代码:
- (void)viewDidLoad { [super viewDidLoad]; // 设置标题 self.navigationItem.title = @"第一个"; UIBarButtonItem *camerBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil]; UIBarButtonItem *secondBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil]; // self.navigationItem.leftBarButtonItem = camerBtn; self.navigationItem.leftBarButtonItems =@[camerBtn,secondBtn]; // 设置返回按钮 #warning 这里是给下一个viewController设置的 UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem =backItem; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
其他两个控制器中代码基本如上,不在详述。
标签:
原文地址:http://www.cnblogs.com/BJTUzhengli/p/5100445.html