TWTweetComposeViewController

TWTweetComposeViewController

因此,使用iOS5中新的Twitter框架,我们可以使用以下简单代码轻松发布Twitter更新:

if ([TWTweetComposeViewController canSendTweet]) {
    TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
    [tweetSheet setInitialText:@"Tweeting from Steamerduck :)"];
    [controller presentModalViewController:tweetSheet animated:YES];
}

但是,我想在用户单击“发送到此处”后执行一些自定义代码:

在TWTweetComposeViewController发送一条推文之后,是否可以执行一些自定义代码和我自己的某些方法?

最佳答案

您可以指定一个完成处理程序,该处理程序在用户编写完该tweet之后被调用。看起来像这样(我还没有机会在设备上进行测试):

if ([TWTweetComposeViewController canSendTweet]) {
    TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
    [tweetSheet setInitialText:@"Tweeting from Steamerduck :)"];

    // Set a completion handler to be called when the user is done
    // composing their tweet

    [tweetSheet setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
        if (result == TWTweetComposeViewControllerResultDone) {
            // Tweet was sent, do something
        } else if (result == TWTweetComposeViewControllerResultCancelled) {
            // Do something else if the user cancelled

            [controller dismissModalViewControllerAnimated:YES];
        }
    }];

    [controller presentModalViewController:tweetSheet animated:YES];
}

10-08 05:45