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.如果视图刷新时,其中的内容没有改变,要考虑内容的数据源是否被变更了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值