不论中间采用了 push->push->present还是present->push->present都可以准确的获取到正在显示的控制器。
//获取当前所展示的控制器
- (UIViewController *)theTopviewControler{
//获取根控制器
UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
UIViewController *parent = rootVC;
//遍历 如果是presentViewController
while ((parent = rootVC.presentedViewController) != nil ) {
rootVC = parent;
}
while ([rootVC isKindOfClass:[UINavigationController class]]) {
rootVC = [(UINavigationController *)rootVC topViewController];
}
return rootVC;
}
网友评论