gpt4 book ai didi

ios - presentingViewController 总是得到 UITabBarController

转载 作者:技术小花猫 更新时间:2023-10-29 11:24:48 28 4
gpt4 key购买 nike

我只是添加了 TabBarController + NavigationController。在此之前一切正常,但现在当我从模态调用 presentingViewController 时,出现此错误:

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

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

在没有 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.

长话短说
1. 在所需的 presentingViewController
上将 definesPresentationContext 设置为 true2. 在所需的 presentedViewController

上将 modalPresentationStyle 设置为 UIModalPresentationCurrentContext

关于ios - presentingViewController 总是得到 UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10907742/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com