I have the following method called when my UITableView reloads:
-(NSArray *)theAccounts {
if (__theAccounts != nil) {
return __theAccounts;
}
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [[NSArray alloc] initWithArray:[accountStore accountsWithAccountType:accountType]];
self.theAccounts = accountsArray;
}
}];
return __theAccounts;
}
Setter Methods in .h:
@property (strong, nonatomic) NSArray *theAccounts;
and in the .m:
@synthesize theAccounts = __theAccounts;
I would like to be able to effectively empty self.theAccounts and reload. So I created a resync method, but it never returns any values after I reload the table:
-(void)resyncAccounts {
self.theAccounts = nil;
[self.tableView reloadData];
}
I am using ARC on iOS 5 SDK. Could this be an issue? I’ve done similar before with fetchedResultsController and had no issues, but that was not ARC. Worth noting that it does return data the first time it is called, and returns __TheAccounts after that, until I try to -(void)resyncAccounts{}.
Why don’t you reload the tableView after setting “theAccounts” in the completion handler? Also, shouldn’t you call “self.theAccounts” after setting it to nil?