push 和 pop 以及模态

1.首先UINavigationcontroller 得持有controller

例如 

   RootViewController *rootVC=[[RootViewController alloc]init];

   UINavigationController *rootNC=[[UINavigationController alloc]initWithRootViewController:rootVC];

    self.window.rootViewController=rootNC;

2.push哪个controller就把哪个controller引入,在点击事件里初始化,

例如

-(void)ItemCount:(UIBarButtonItem *)sender

{

    FirstViewController *fies=[[FirstViewController alloc]init];

    [self.navigationController pushViewController:fies animated:YES];

}

 3.返回即pop  首先设置

self.navigationItem.title=@"根视图";

    UIBarButtonItem *b1=[[UIBarButtonItem alloc]initWithTitle:@"下一张" style:UIBarButtonItemStyleDone target:self action:@selector(ItemCount:)];

    self.navigationItem.rightBarButtonItem=b1;

  然后在barbutton事件里实现pop的功能

-(void)ItemCount:(UIBarButtonItem *)sender

{

    [self.navigationController popToRootViewControllerAnimated:YES];

}

 

4.模态

push的时候一样 

-(void)button2Action:(UIButton *)sender

{

GreenViewController *green=[[GreenViewController alloc]init];

//模态视图  临时弹出

    [self presentViewController:green animated:YES completion:nil];

}

 

一,设置一个button  有点击事件( 不用navigationcontroller持有,)

二,事件里退回模态就OK了

-(void)buttonAction:(UIButton *)sender

{

    //退出模态

    [self dismissViewControllerAnimated:YES completion:nil];  

}

 

posted @ 2014-12-09 11:07  *宁宁  阅读(226)  评论(0编辑  收藏  举报