dismissViewControllerAnimated之后的presentViewController

时间:2013-05-27 08:12:21

标签: ios uiviewcontroller

我在解除视图控制器后尝试呈现视图控制器(SLServiceTypeFacebook)。喜欢这个

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

    ////////////////////////////////////
    //Some Stuff Other Calculations//
    ////////////////////////////////////
    //Then

    if([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook])
    {
        // Facebook Service Type is Available

        SLComposeViewController *slVC   =   [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeFacebook];
        SLComposeViewControllerCompletionHandler handler    =   ^(SLComposeViewControllerResult result)
        {
            if (result == SLComposeViewControllerResultCancelled)
            {
                NSLog(@"Cancelled");

            }
            else
            {
                NSLog(@"Done");
            }

            [slVC dismissViewControllerAnimated:NO completion:Nil];
        };
        slVC.completionHandler = handler;
        [slVC setInitialText:post[@"user_fullname"]];
        [slVC addURL:[NSURL URLWithString:post[@"url"]]];

        [self presentViewController:slVC animated:NO completion:Nil];
    }

但这似乎不起作用。 Facebook模式会自动取消。

我是否在概念上做错了什么?

2 个答案:

答案 0 :(得分:4)

像这样使用完成块:

[self dismissViewControllerAnimated:NO completion:^{

   //SHOW YOUR NEW VIEW CONTROLLER HERE!
}];

您错过了上面的完成处理程序。

答案 1 :(得分:0)

尝试一下:

[self dismissViewControllerAnimated:NO completion:^{
    NewViewController *viewController = [[NewViewController alloc]initWithNibName:NSStringFromClass([NewViewController class]) bundle:nil];
    UIViewController *topRootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topRootViewController.presentedViewController)
    {
        topRootViewController = topRootViewController.presentedViewController;
    }

    [topRootViewController presentViewController:viewController animated:YES completion:nil];
}];