美文网首页
iOS APPdelegate里面跳转某个控制器

iOS APPdelegate里面跳转某个控制器

作者: 天顾有情人_strive | 来源:发表于2017-06-24 15:50 被阅读14次

1.

- (UIViewController*)topViewController

{

return [self topViewControllerWithRootViewController:self.keyWindow.rootViewController];

}

- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController

{

if ([rootViewController isKindOfClass:[UITabBarController class]]) {

UITabBarController *tabBarController = (UITabBarController *)rootViewController;

return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];

} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {

UINavigationController* navigationController = (UINavigationController*)rootViewController;

return [self topViewControllerWithRootViewController:navigationController.visibleViewController];

} else if (rootViewController.presentedViewController) {

UIViewController* presentedViewController = rootViewController.presentedViewController;

return [self topViewControllerWithRootViewController:presentedViewController];

} else {

return rootViewController;

}

}

2.你就可以实例化跳转了[[self topViewController].navigationController pushViewController:login animated:YES];

二、

- (UIViewController *)getCurrentVC

{

UIViewController *result = nil;

UIWindow * window = [[UIApplication sharedApplication] keyWindow];

if (window.windowLevel != UIWindowLevelNormal)

{

NSArray *windows = [[UIApplication sharedApplication] windows];

for(UIWindow * tmpWin in windows)

{

if (tmpWin.windowLevel == UIWindowLevelNormal)

{

window = tmpWin;

break;

}

}

}

UIView *frontView = [[window subviews] objectAtIndex:0];

id nextResponder = [frontView nextResponder];

if ([nextResponder isKindOfClass:[UIViewController class]])

result = nextResponder;

else

result = window.rootViewController;

return result;

}

相关文章

网友评论

      本文标题: iOS APPdelegate里面跳转某个控制器

      本文链接:https://www.haomeiwen.com/subject/shekcxtx.html