gpt4 book ai didi

ios - 呈现 View Controller 时的 UIViewControllerHierarchyInconsistency

转载 作者:行者123 更新时间:2023-11-29 12:28:28 24 4
gpt4 key购买 nike

我有这样的 View Controller 结构:UINavigationController(root view controller)->UIViewController .在我的 UIViewController我有UITableView与动态细胞。在每个单元格中都有全屏显示的“分享”按钮 UIWindow .这UIWindow包含一个 UIView带有社交网络按钮,每个按钮都必须显示共享对话框,并且仅适用于与社交网络框架或库一起使用的按钮一切正常,但我有一个必须显示自定义共享对话框的按钮。当我按下它时,我的应用程序崩溃并出现以下错误:*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'adding a root view controller <REComposeViewController: 0x7f9e8b416260> as a child of view controller:<AVMNavCon: 0x7f9e887540f0>'

这就是我尝试显示对话框的方式:

-(void)shareWithLinkedIn:(AVMSocNetButton*)sender{
[self closeWhiteView]; // close UIWindow with social network buttons
REComposeViewController *composeViewController = [[REComposeViewController alloc] init]; // define and initialize custom share dialog
composeViewController.title = @"Social";
composeViewController.hasAttachment = YES;
composeViewController.attachmentImage = sender.shareImage;
composeViewController.text = [NSString stringWithFormat:@"Share text"];
testWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 74, SCREEN_WIDTH-10, SCREEN_HEIGHT/2)];
testWindow.windowLevel = UIWindowLevelStatusBar;
testWindow.hidden = NO;

testWindow.rootViewController = composeViewController;
[composeViewController presentFromRootViewController];

[self performSelector:@selector(showShareWindow) withObject:nil afterDelay:1];
}

大家可以看到这里我用了另一个UIWindow (测试窗口)。这是因为如果我在没有 UIWindow 的情况下显示我的对话框我的UIViewController将消失,我将在黑色背景上看到共享对话框。然后,如果我注释行 testWindow.rootViewController = composeViewController;我会根据需要看到我的共享对话框,但没有任何交互(我无法触摸屏幕上任何地方的按钮) 我应该如何呈现我的对话框并避免此错误?

编辑:

完整的层次结构是:UINavigationController -> UIViewController -> UITableView -> UITableViewCell -> UIButton ->(调用“WhiteView”UIWindow)->UIWindow -> UIButton ->(调用 shareWithLinkedIn 方法)

最佳答案

您不应该尝试将窗口的 Root View Controller 用作模式。如果你想使用窗口实现这个转换,那么使用一个空的 UIViewController 和一个清晰的背景作为 rootViewController 然后将你的 composeViewController 呈现为模态。

您可以在不使用 Windows 的情况下完成您想要做的事情。例如在 iOS 8 上,将 UIModalPresentationOverFullScreen 用作 composeViewControllermodalPresentationStyle 并简单地将其呈现为当前 Controller 的模态。同样,您需要一个透明的容器 View 来执行此操作,但它比引入另一个窗口更清晰。在 iOS 7 上,您需要使用 UIModalPresentationCustom(默认情况下似乎与 UIModalPresentationOverFullScreen 具有相同的效果)

关于ios - 呈现 View Controller 时的 UIViewControllerHierarchyInconsistency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28403204/

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