UIViewController *rootVC = self.presentingViewController;
while (rootVC.presentingViewController) {
rootVC = rootVC.presentingViewController;
}
[rootVC dismissViewControllerAnimated:YES completion:nil];
本文提供了一段Objective-C代码示例,用于递归地查找并关闭当前显示的最顶层视图控制器。通过利用presentingViewController属性,该方法可以应用于各种嵌套的模态视图控制器场景。
UIViewController *rootVC = self.presentingViewController;
while (rootVC.presentingViewController) {
rootVC = rootVC.presentingViewController;
}
[rootVC dismissViewControllerAnimated:YES completion:nil];
952
573

被折叠的 条评论
为什么被折叠?