IOS push与pop的跨界面跳转

时间:2026-02-16 23:10:02

1、创建四个控制器VC。

第一个界面,添加按钮点击跳转事件,跳转到界面2.

界面2,点击事件跳转到界面4。

2、界面4此刻如果是pop则直接返回界面2。我们想要pop返回到界面3,界面3在pop到界面1.

即:self.navigationController中原本是:界面1,界面2,界面4,我们跳转到界面4后想要self.navigationController变成界面1,界面3,界面4.

3、核心代码在于界面2,push后就要修改self.navigationController.viewControllers。

在跳转事件中添加:

NSMutableArray *tempMarray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];    [tempMarray insertObject:thirdVC atIndex:tempMarray.count - 2];    [tempMarray removeObject:self];    [self.navigationController setViewControllers:tempMarray animated:YES];

把navigationController中的界面2删除,新增界面3.

4、最终展示效果为

项目demo下载:https://pan.baidu.com/s/1slaRxTV

IOS push与pop的跨界面跳转

© 2026 途途旅游
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com