这是我的代码:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *viewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; //Tell him with what social platform to use it, e.g. facebook or twitter
[viewController setInitialText:sQuotes];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navController presentViewController:viewController animated:YES completion:nil];
[viewController setCompletionHandler:^(SLComposeViewControllerResult result)
{
NSString *output;
switch (result)
{
case SLComposeViewControllerResultCancelled:
output = @"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
{
output = @"Post Successfull";
}
break;
default:
break;
}
[appDelegate.navController dismissViewControllerAnimated:YES completion:nil];
}];
}
但它会显示警告
其视图不在窗口层次结构中!
答案 0 :(得分:1)
警告很清楚。您试图通过不在窗口层次结构中的视图来呈现模式视图,这将不起作用。
尝试更改此[appDelegate.navController presentViewController:viewController animated:YES completion:nil];
代替这样的事情:
[appDelegate.window.rootViewController presentViewController:viewController animated:YES completion:nil];
这可以保证您应用的当前活动根视图控制器将是呈现模态视图控制器的控制器。
根据AppDelegate的构建方式,您可能需要添加一个属性或只是一个getter来将window
变量显示给外界。