Appdelegate 跳转其他页面 获取当前屏幕显示的viewcontroller 获取当前屏幕中present出来的viewcontroller 获取当前导航控制器
Appdelegate 跳转其他页面
UITabBarController *tab = (UITabBarController *)_window.rootViewController;
UINavigationController *nav = tab.viewControllers[tab.selectedIndex];
MessageViewController *vc = [[MessageViewController alloc] init]; 需要跳转的页面
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
//获取当前屏幕显示的viewcontroller
- (UIViewController *)getCurrentVC{
UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
if (!window) {
return nil;
}
UIView *tempView;
for (UIView *subview in window.subviews) {
if ([[subview.classForCoder description] isEqualToString:@"UILayoutContainerView"]) {
tempView = subview;
break;
}
}
if (!tempView) {
tempView = [window.subviews lastObject];
}
id nextResponder = [tempView nextResponder];
while (![nextResponder isKindOfClass:[UIViewController class]] || [nextResponder isKindOfClass:[UINavigationController class]] || [nextResponder isKindOfClass:[UITabBarController class]]) {
tempView = [tempView.subviews firstObject];
if (!tempView) {
return nil;
}
nextResponder = [tempView nextResponder];
}
return (UIViewController *)nextResponder;
}
//获取当前屏幕中present出来的viewcontroller。
- (UIViewController *)getPresentedViewController
{
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = appRootVC;
if (topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
return topVC;
}
// 获取当前导航控制器
- (BaseNavigationController *)getNavController{
BaseTableBarControllerView *tabVC = (BaseTableBarControllerView *)self.window.rootViewController;
tabVC.selectedIndex = 2;
BaseNavigationController *pushClassStance = (BaseNavigationController *)tabVC.selectedViewController;
return pushClassStance;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步