获取当前屏幕显示的视图控制器viewcontroller
2016-03-30 17:46
645 查看
//获取当前屏幕显示的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;
}
- (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;
}
相关文章推荐
- javaEE 初步实现分页
- 【dotnet跨平台】如何启用远程访问asp.net mvc 5网站并指定端口?
- Python线程event
- myeclipse安装svn插件的多种方式
- C++ 取得系统当前时间
- 使用Java语言完成数据报之间的通信即使用udp数据传输
- CIFilter 的多种滤镜效果
- git Pull Request
- python--基础学习(四)自然字符串、重复字符串、子字符串
- 常用的adb命令
- JspSmartUpload上传下载
- checkbox全选/全不选
- ubuntu下安装matlab
- lvchange的available參数
- UVALive 6088 Approximate Sorting 构造题
- 怎么写苹果ios应用加急审核理由?分享我的加速审核理由技巧
- Django中的request与response对象
- LeetCode 59. Spiral Matrix II
- acitvity的runOnUiThread方法
- Qt之线程(QThread)