1.我们在非视图类中想要随时展示一个vIEw时,需要将被展示的vIEw加到当前vIEw的子视图,或用当前vIEw presentVIEwController,或pushVIEwContrller,这些 *** 作都需要获取当前正在显示的VIEwController。
//获取当前屏幕显示的vIEwcontroller- (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;}
2.获取当前屏幕中present出来的vIEwcontroller。
- (UIVIEwController *)getPresentedVIEwController{ UIVIEwController *appRootVC = [UIApplication sharedApplication].keyWindow.rootVIEwController; UIVIEwController *topVC = appRootVC; if (topVC.presentedVIEwController) { topVC = topVC.presentedVIEwController; } return topVC;}总结
以上是内存溢出为你收集整理的iOS 获取当前正在显示的ViewController全部内容,希望文章能够帮你解决iOS 获取当前正在显示的ViewController所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)