【发布时间】:2012-12-17 18:08:28
【问题描述】:
从块中显示 UIAlertView 的最佳方式是什么?
我的代码中有以下操作:
- (IBAction)connectWithTwitterClicked:(id)sender {
ACAccountStore * account = [[ACAccountStore alloc]init];
ACAccountType * accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == YES){
NSLog(@"Twitter account has been granted");
NSArray * arrayOfAccounts = [account accountsWithAccountType:accountType];
if([arrayOfAccounts count] > 0){
ACAccount * twitterAccount = [arrayOfAccounts lastObject];
NSLog(@"Found twitter Id of [%@]", twitterAccount.username);
// continue on to use the twitter Id
} else {
// no twitter accounts found, display alert to notify user
}
} else{
NSLog(@"No twitter accounts have been granted");
// no twitter accounts found, display alert to notify user
}
}];
}
到目前为止,我已经尝试过这些解决方案:
- 在 2 条注释行中的任何一条上,直接创建并显示 UIAlertView,这会使应用程序崩溃,我相信这是由于 该块是一个异步进程并且无法访问 用于显示警报的 UI 线程
- 在块外创建了一个 NSMutableString,用
__block,设置在注释行后显示。 类似的问题在这里块是异步运行的 显示警报的时间无法保证 NSMutableString 已设置。
谁能提出解决方案?我希望能够以某种方式通知用户,这样他们就可以不使用 twitter,或者在设备设置中设置一个帐户。
谢谢
【问题讨论】:
标签: objective-c ios ios6 twitter objective-c-blocks