【发布时间】:2014-07-21 04:38:22
【问题描述】:
警告:尝试呈现不在窗口层次结构中的视图!
是的,在发布此问题之前,我已经查看了其他问题和答案。他们没有帮助我解决这个问题。这就是我正在做的事情。我正在调用我的单例类 socialHelper 来显示一个操作表,其中 postToFacebook 方法是一个可供选择的选项。单击此操作时,我收到上面的警告,并且不显示 postToFacebook。我从 UIViewController 中调用它,UINavigationController 作为主控制器,我的 SocialHelper 类是 NSOject。
- (void)postToFacebook
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[slComposeViewController setInitialText:@"Building stairs? Checkout StairsPro on the app store!"];
[slComposeViewController addImage:[UIImage imageNamed:@"StairsIcon120x120.png"]];
[slComposeViewController addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/stairs-pro/id477032819?ls=1&mt=8"]];
[self presentViewController:slComposeViewController animated:YES completion:nil];
// I've also tried this, which shows the post window, but after hitting cancel or post, my previous viewController is not the current viewController. So my navigation bar is gone and can't move around in my app.
// [[[[UIApplication sharedApplication]delegate]window]setRootViewController:slComposeViewController];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Facebook Account" message:@"No Facebook account has been configured. You can configure or create a Facebook account in settings." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
}
所以我要问的是在这种情况下让slComposerViewController 显示的最佳方式是什么,以及我们如何使用UIApplication 选项。谢谢!
【问题讨论】:
-
SocialHelper真的在屏幕上吗? -
当它被调用到 PostToFacebook 窗口时,屏幕上什么也没有显示。只是我调用它的屏幕。但是 UActionSheet 有效,然后我点击 Post to Facebook,我收到警告,UIActionSheet 消失,然后回到我调用它的屏幕。
-
presentViewController:animated:completion:需要从当前显示在屏幕上的 viewController 调用。如果SocialHelper不是当前呈现的viewController,那么你不应该在它上面调用这个方法 -
我尝试将所有内容移动到正在显示的 UIViewController 类并得到相同的警告。
-
你确定你有正确的viewController吗?
标签: ios uiviewcontroller hierarchy