我正在尝试实现一种方法,让用户从他们在 iPhone(iOS5 及更高版本)上设置的 Twitter 帐户中进行选择。我可以让用户名出现在 UIActionSheet 中,但由于某种原因,UIActionSheet 在调用该方法后需要大约 5 秒才能出现。
我想可能是因为检索 Twitter 帐户列表需要一段时间,但在我的日志中它们会立即出现,所以不是这样。
有任何想法吗?
- (void)TwitterSwitch {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSMutableArray *buttonsArray = [NSMutableArray array];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
NSLog(@"%@", accountsArray);
[accountsArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[buttonsArray addObject:((ACAccount*)obj).username];
}];
NSLog(@"%@", buttonsArray);
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
for( NSString *title in buttonsArray)
[actionSheet addButtonWithTitle:title];
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons-1;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}];
}