简体   繁体   English

presentViewController总是获取UITabBarController

[英]presentingViewController getting always UITabBarController

I just add TabBarController + NavigationController. 我只是添加TabBarController + NavigationController。 Previous to this everything was ok but now when I call presentingViewController from a modal, I get this error: 在此之前一切都还可以但是现在当我从一个模态调用presentViewController时,我收到此错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController tableViewListado]: unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UITabBarController tableViewListado]:无法识别的选择器发送到实例

Instead of receiving the expected object (ViewController) I'm getting "UITabBarController", should I get the presenting controller in some different way when using TabBar and Nav controllers? 而不是接收预期的对象(ViewController)我得到“UITabBarController”,我是否应该在使用TabBar和Nav控制器时以不同的方式获得呈现控制器?

Without the TabBar/Nav I was using this: 没有TabBar / Nav,我使用了这个:

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

[parentView something];

Edit: 编辑:

Just find out that if I do this it works, but dont think this is actually the best way to do it: 只是发现如果我这样做它有效,但不要认为这实际上是最好的方法:

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

[parentView something];

copy of my answer from this question 我的答案副本来自这个问题

from Programming iOS 6, by Matt Neuburg : 来自Matt Neuburg编程的iOS 6

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. 在iPad上,当呈现的视图控制器的modalPresentationStyle是UIModalPresentationCurrentContext时,必须决定哪个视图控制器应该是呈现的视图控制器的presentViewController。 This will determine what view will be replaced by the presented view controller's view. 这将确定将由所呈现的视图控制器视图替换的视图。 This decision involves another UIViewController property, definesPresentationContext (a BOOL). 此决定涉及另一个UIViewController属性,definePresentationContext(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. 从发送了presentViewController:animated:completion:的视图控制器开始,我们走向父视图控制器链,寻找其definePresentationContext属性为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. 它将是presentsViewController,它的视图将被呈现的视图控制器视图所取代。 If we don't find one, things work as if the presented view controller's modalPresentationStyle had been UIModalPresentationFullScreen. 如果我们找不到,那么就像所呈现的视图控制器的modalPresentationStyle是UIModalPresentationFullScreen一样。

TL;DR TL; DR
1. set definesPresentationContext to true on the desired presentingViewController 1.集definesPresentationContext为true期望presentingViewController
2. set modalPresentationStyle to UIModalPresentationCurrentContext on the desired presentedViewController 2.组modalPresentationStyleUIModalPresentationCurrentContext期望presentedViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM