在这一点上,我很沮丧,但我确定这是我所缺少的。在这段代码中,我的新 viewController 的 segue 在函数的其余部分执行后显示。如何让我的 viewController 成为正在执行的代码?基本上阻止 tweetText 函数发生,直到该视图关闭我试图给用户一个选项来选择一个 Twitter 帐户,如果有多个帐户。我尝试了很多不同的方法。在 Apple 自己的示例代码中,他们建议给用户一个选项,但不提供任何关于如何做到这一点的信息,而无需浏览其余代码。
这是代码:
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
dispatch_sync(dispatch_get_main_queue(), ^{
// Get the list of Twitter accounts.
self.accountsArray = [accountStore accountsWithAccountType:accountType];
if([self.accountsArray count] > 1 /* Check method to see if preference is still a valid account */) {
// Display user accounts if no preference has been set
[self performSegueWithIdentifier:@"TwitterAccounts" sender:self.accountsArray];
[tweet tweetText:tweetString account:self.twitterAccount type:AchievementTweet];
} else {
[tweet tweetText:tweetString account:[self.accountsArray lastObject] type:AchievementTweet];
}
});
} else {
[tweet performSelectorOnMainThread:@selector(displayText:) withObject:[NSNumber numberWithInt:403] waitUntilDone:NO];
}
}];