【问题标题】:presentViewController after dismissViewControllerAnimated在dismissViewControllerAnimated 之后的presentViewController
【发布时间】:2019-07-12 19:58:24
【问题描述】:

我试图在关闭视图控制器后呈现视图控制器 (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 模态会自动取消。

我在概念上做错了吗?

【问题讨论】:

  • 你想关闭 slVC 视图控制器还是 self.presentingViewController ??
  • self.presentingViewController,然后在一些其他代码之后呈现 slVC,但我不知道为什么 SLComposeViewControllerResultCancelled 不断触发自身

标签: ios uiviewcontroller


【解决方案1】:

像这样使用完成块:

[self dismissViewControllerAnimated:NO completion:^{

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

您缺少上面的完成处理程序。

【讨论】:

  • NSLog out 完成块中的每个步骤,这绝对有效,因为我在使用模态 VC 时到处都使用它。在这种情况下,块中的某些东西失败了。
  • Dev2rights,我已经这样做了。它的打印已取消。请参考代码
  • 好的,我明白了,你的调用'[slVC dismissViewControllerAnimated:NO completion:Nil];'在您的处理程序块中。删除它。
  • 好吧,无论如何,它不应该在那里。根据文档,这意味着没有可用的用户帐户。你让用户登录 facebook 吗? developer.apple.com/library/ios/#documentation/…
  • 好的,那么最后的事情就是我说你没有为 url 设置一个有效的 [NSURL],它不仅仅是你添加的一个字符串。请参阅这篇文章以了解其在 twitter 实现中的使用方式:stackoverflow.com/questions/13428304/…
【解决方案2】:

试试这个:

[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];
}];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多