presentViewController总是获取UITabBarController

dim*_*irc 9 ios ios5

我只是添加TabBarController + NavigationController.在此之前一切都还可以但是现在当我从一个模态调用presentViewController时,我收到此错误:

由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UITabBarController tableViewListado]:无法识别的选择器发送到实例

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

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

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

[parentView something];
Run Code Online (Sandbox Code Playgroud)

编辑:

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

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

[parentView something];
Run Code Online (Sandbox Code Playgroud)

cal*_*kos 5

我对这个问题的回答的副本

来自Programming iOS 6,作者Matt Neuburg

在iPad上,当显示的视图控制器的modalPresentationStyle为UIModalPresentationCurrentContext时,必须确定哪个视图控制器应作为显示的视图控制器的presentingViewController。这将确定将由呈现的视图控制器的视图替换哪个视图。该决定涉及另一个UIViewController属性definePresentationContext(一个BOOL)。从将presentViewController:animated:completion:发送到的视图控制器开始,我们沿着父级视图控制器的链,寻找其definePresentationContext属性为YES的视图控制器。如果我们找到一个,那就是那个。它将是presentingViewController,其视图将由所呈现的视图控制器的视图替换。如果我们找不到一个,

TL; DR
1组definesPresentationContext对真正期望的presentingViewController
2组modalPresentationStyleUIModalPresentationCurrentContext所期望的presentedViewController