iOS 页面跳转和返回,持续编写

如果使用导航
第一个按钮方法:
[self.navigationController pushViewController:secondVC animated:YES];
第二个按钮方法:
[self.navigationController popViewControllerAnimated:YES];

如果使用模态
第一个按钮方法:
[self presentViewController:secondVC animated:YES completion:nil];
第二个按钮方法:
[self dismissViewControllerAnimated:YES completion:nil]; 

[self dismissViewControllerAnimated:YES completion:^{}];

直接跳转到首页
模态

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion:nil];
导航栏
 [self.navigationController popToRootViewControllerAnimated:YES];
在页面中重写返回按钮事件

- (void)viewDidLoad {

    [super viewDidLoad];

  UIButton * back =[UIButton addBtnImage:@"back" AndFrame:CGRectMake(0, 0, 30, 30) WithTarget:self action:@selector(leftBtnClick)];

self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]initWithCustomView:back];
}

#pragma mark-->  返回点击事件


-(void)leftBtnClick{

NSLog(@"返回按钮点击事件");

这里是返回三层前,1234,4->1

 int index = (int)[[self.navigationController viewControllers]indexOfObject:self];

    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index -3)] animated:YES];

}

//跳到上一层的上一层

//    UIViewController *viewCtl = self.navigationController.viewControllers[1];


//    [self.navigationController popToViewController:viewCtl animated:YES];



https://blog.csdn.net/u011096206/article/details/50606778


1.从视图A中navigation controller push到视图B,当视图B navigationcontroller pop回到视图A时,并不会调用A的viewDidLoad,但是会调用viewWillAppear,所以如果视图A有需要变更的内容应该在viewWillAppear中实现。


2.当一个视图生成时是先调用viewDidLoad,再调用viewWillAppear的。


3.如果视图刷新时,其中的内容没有改变,要考虑内容的数据源是否被变更了

 

posted on 2017-12-28 14:48  高彰  阅读(860)  评论(0编辑  收藏  举报

导航