ios – presentsViewController总是获取UITabBarController

前端之家收集整理的这篇文章主要介绍了ios – presentsViewController总是获取UITabBarController前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我只是添加了TabBarController NavigationController.在此之前一切都还可以,但现在当我从一个模态调用presentViewController时,我收到此错误

Terminating app due to uncaught exception
‘NSInvalidArgumentException’,reason: ‘-[UITabBarController
tableViewListado]: unrecognized selector sent to instance

而不是接收预期的对象(ViewController)我得到“UITabBarController”,我是否应该在使用TabBar和Nav控制器时以不同的方式获得呈现控制器?

没有TabBar / Nav,我使用了这个:

ViewController *parentView = (ViewController *)[self presentingViewController]; 

[parentView something];

编辑:

只是发现如果我这样做它有效,但不要认为这实际上是最好的方法

ViewController *parentView = (ViewController *)[(UINavigationController *)[((UITabBarController *)[self presentingViewController] ) selectedViewController] topViewController]  ;

[parentView something];

解决方法

我的答案副本来自 this question

Programming iOS 6,by Matt Neuburg开始:

On the iPad,when the presented view controller’s modalPresentationStyle is UIModalPresentationCurrentContext,a decision has to be made as to what view controller should be the presented view controller’s presentingViewController. This will determine what view will be replaced by the presented view controller’s view. This decision involves another UIViewController property,definesPresentationContext (a BOOL). Starting with the view controller to which presentViewController:animated:completion: was sent,we walk up the chain of parent view controllers,looking for one whose definesPresentationContext property is YES. If we find one,that’s the one; it will be the presentingViewController,and its view will be replaced by the presented view controller’s view. If we don’t find one,things work as if the presented view controller’s modalPresentationStyle had been UIModalPresentationFullScreen.

TL; DR1.在所需的presentsViewController上将definePresentationContext设置为true2.在所需的presentViewController上将modalPresentationStyle设置为UIModalPresentationCurrentContext

原文链接:https://www.f2er.com/iOS/334308.html

猜你在找的iOS相关文章