ios 下获取 rootviewcontroller 的版本不同的问题解决办法
一般 原生的
[[uiapplication sharedapplication].keywindow.rootviewcontroller presentmodalviewcontroller:self animated:no];
可以 获取 系统的 rootviewcontroller
但 cocos2d-x 2.1.1 在 appcontroller.mm 内定义的 加载方法是
// set rootviewcontroller to window if ( [[uidevice currentdevice].systemversion floatvalue] < 6.0) { // warning: addsubview doesn't work on ios6 [window addsubview: viewcontroller.view]; } else { // use this method on ios6 [window setrootviewcontroller:viewcontroller]; }
也就是说 只有在 ios6 下 才设置rootview 其他时候是 使用addsubview的方法 加载。
所以 相应的 获取 rootviewcontroller方法 要改为。
if ( [[uidevice currentdevice].systemversion floatvalue] < 6.0) { // warning: addsubview doesn't work on ios6 nsarray* array=[[uiapplication sharedapplication]windows]; uiwindow* win=[array objectatindex:0]; uiview* ui=[[win subviews] objectatindex:0]; uiviewcontroller* ctrol=(uiviewcontroller*)[ui nextresponder]; } else { // use this method on ios6 uiviewcontroller* ctrol=[uiapplication sharedapplication].keywindow.rootviewcontroller]; }
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
如对本文有疑问, 点击进行留言回复!!
APP调用微信小程序,能拉起小程序,但是onResp回调不会被调用问题
Codeforces Round #657 (Div. 2) B. Dubious Cyrpto(思维,数学)
网友评论