模态
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
//将要出现
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
//已经消失的方法
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"%@",self.navigationController.viewControllers);
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
//自定义naviagtionBar
[self customNavigationBar];
//布局button
//[self layoutButton];
}
//布局button
-(void)layoutButton
{
UIButton *bt = [UIButton buttonWithType:UIButtonTypeSystem];
[bt setTitle:@"Next" forState:UIControlStateNormal];
bt.frame = CGRectMake(240, 64, 80, 40);
bt.backgroundColor = [UIColor yellowColor];
//点击事件
[bt addTarget:self action:@selector(push:) forControlEvents:UIControlEventTouchUpInside];
//添加父试图
[self.view addSubview:bt];
//不释放
}
//自定义naviagtionBar
-(void)customNavigationBar
{
self.navigationItem.title = @"firstVC";
//设置rightbarbuttonitem
//创建对象
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(rightItemAction:)];
//赋值
self.navigationItem.rightBarButtonItem = rightItem;
}
-(void)rightItemAction:(UIBarButtonItem *)rightItem
{
NSLog(@"右边Ttem");
//创建下一个控制器对象
SecondViewController *scondVC = [[SecondViewController alloc]init];
//视同导航视图控制器push下一个控制器
[self.navigationController pushViewController:scondVC animated:YES];
//释放
[scondVC release];
}
-(void)push:(UIButton *)button
{
//创建下一个试图控制器对象
SecondViewController *secVC = [[SecondViewController alloc]init];
//使用第一个试图控制器推出下一个跟试图控制器
[self.navigationController pushViewController:secVC animated:YES];
//释放
[secVC release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

浙公网安备 33010602011771号