iOS Objective-C 实现两层返回导航
iOS Objective-C 实现两层返回导航
在 iOS 应用中,使用 Objective-C 代码实现两层返回导航功能非常简单。以下方法可以帮助你实现:
1. 设置根视图控制器
在第一层(根视图控制器)中,将第二层(目标视图控制器)设置为导航控制器的根视图控制器。
TargetViewController *targetVC = [[TargetViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:targetVC];
[self presentViewController:navigationController animated:YES completion:nil];
2. 返回到根视图控制器
在第二层(目标视图控制器)中,使用以下代码返回到第一层(根视图控制器)。
[self.navigationController popToRootViewControllerAnimated:YES];
这样,当你在第二层点击返回按钮时,会直接返回到第一层。
原文地址: https://www.cveoy.top/t/topic/qorv 著作权归作者所有。请勿转载和采集!