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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...