gpt4 book ai didi

iOS:警告 "attempt to present ViewController whose view is not in the window hierarchy"

转载 作者:IT老高 更新时间:2023-10-28 11:45:21 29 4
gpt4 key购买 nike

当我尝试在导航 Controller 上显示 ActivityController 时收到以下警告,

Attempt to present <UIActivityViewController: 0x15be1d60> on <UINavigationController: 0x14608e80> whose view is not in the window hierarchy!

我已尝试通过以下代码呈现 View Controller ,

UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;

UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: activityController animated: YES completion:nil];

[activityController setCompletionHandler:^(NSString *activityType, BOOL completed) {
NSLog(@"completed");

}];

这里出了什么问题?

最佳答案

您正在尝试从 rootViewController 呈现 View Controller 。在您的情况下,我认为 rootViewController 不是当前的 ViewController。您在其上展示或推送了一个新的 UIViewController。您应该从最顶层的 View Controller 本身呈现一个 View Controller 。

你需要改变:

UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: activityController animated: YES completion:nil];

到:

[self presentViewController: activityController animated: YES completion:nil];

关于iOS:警告 "attempt to present ViewController whose view is not in the window hierarchy",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28379327/

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