标题
UINavigationController的创建和应用
#import "MainViewController.h"
先创建一个viewController
MainViewController *mainVC = [[MainViewController alloc]init];
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
self.window.rootViewController = naVC;
[naVC release];
[mainVC release];
在视图控制器中添加控件 控件的加载内容不详述
//这里的button是为了实现点击跳转的方法
[button setTitle:@"下一页" forState:UIControlStateNormal]
[self.view addSubview:button]
button.layer.borderWidth = 1
button.layer.cornerRadius = 10
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]
对UINavigationController进行设置
self.title = @"猫眼电影";
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
self.navigationController.navigationBar.translucent = NO;
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(barButtonAction:)] autorelease];
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 40, 40);
[rightButton setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
实现按钮的点击事件 这里有两种跳转方法模态跳转和导航视图控制器的跳转(可以通过属性传值)
SecondViewController *secVC = [[SecondViewController alloc]init];
[secVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:secVC animated:YES completion:^{
}];
[secVC release];
通过导航视图控制器进行跳转
创建下一页对象
SecondViewController *secVC = [[SecondViewController alloc]init];
[self.navigationController pushViewController:secVC animated:YES];
[secVC release];
secVC.number = 100;
secVC.str = self.myTextField.text;
secVC.arr = @[@"杨林",@"刘山山"];
从后往前跳转 需要在被跳转页写方法
-(void)click:(UIButton *)button{
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];