【问题标题】:Present View Controller After Completed Twitter Call完成 Twitter 调用后显示视图控制器
【发布时间】:2014-10-27 07:08:22
【问题描述】:

我正在尝试在 Twitter 帖子成功完成后呈现模式视图;但是,我无法展示我的控制器,因为 SLComposeViewController 仍在展示。是否有一些完成方法会在所有内容都完成并且视图被关闭时调用?

SLComposeViewController* tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    tweetSheet.completionHandler = ^(SLComposeViewControllerResult result){
        UBSTwitterSuccessViewController* twitterView;
        switch(result){
            case SLComposeViewControllerResultCancelled:
                break;
            case SLComposeViewControllerResultDone:
                twitterView = [[UBSTwitterSuccessViewController alloc]initWithNibName:XIBTWITTERSUCCESS bundle:nil];
                [self presentViewController:twitterView animated:YES completion:nil];
                break;
        }
    };
    [tweetSheet setInitialText:@"Check out this cool thing"];
    [tweetSheet addURL: [NSURL URLWithString:@"http://www.cad-comic.com/"]];

    [self presentViewController:tweetSheet animated:NO completion:nil];

没有视图的警告:

Warning: Attempt to present <UBSTwitterSuccessViewController: 0x16569b70>  on <UINavigationController: 0x1663bd30> which is already presenting <SLComposeViewController: 0x166b1170>

【问题讨论】:

    标签: objective-c ios7 twitter modalviewcontroller slcomposeviewcontroller


    【解决方案1】:

    SLComposeViewController 具有completionHandler,您可以在其中分配一个块,以便在用户完成或取消撰写帖子时执行。

    completionHandler 用户完成撰写时要调用的处理程序 一个帖子。

    @property(非原子,复制)SLComposeViewControllerCompletionHandler 完成处理程序讨论处理程序有一个参数, 指示用户是完成还是取消了撰写帖子。 不保证在任何特定线程上调用此块。

    特殊注意事项在 iOS 6 及更早版本中,如果您设置了完成 处理程序,然后您的完成处理程序负责解除 SLComposeViewController 使用 解除视图控制器动画:完成:。在 iOS 7 及更高版本中 使用 iOS 7 或更高版本的 SDK 编译,您不能关闭 完成处理程序中的 SLComposeViewController - 系统将执行 如此自动。

    Apple Documentation

    【讨论】:

    • 我正在使用completionHandler,但问题是在完成处理程序运行时SLComposeViewController仍在呈现,因此呈现另一个视图控制器失败。
    • 你必须先关闭tweetSheetcase SLComposeViewControllerResultDone: [self dismissViewControllerAnimated:YES completion:^{ twitterView = [[UBSTwitterSuccessViewController alloc] initWithNibName:XIBTWITTERSUCCESS bundle:nil]; [self presentViewController:twitterView animated:YES completion:nil]; }];
    • “在 iOS 7 和更高版本中,当使用 iOS 7 或更高版本的 SDK 编译时,您不能在完成处理程序中关闭 SLComposeViewController - 系统会自动执行此操作。”我正在为 iOS 7 编写代码。
    猜你喜欢
    • 2012-10-27
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多