(iOS 5) while receiving a list of Twitter accounts, does TableView freeze?

I am trying to get a list of twitter accounts to load a UITableViewController that contains data. I am using this function:

- (void)viewDidLoad { [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { ... [[self tableView] insertRowsAtIndexPaths ...]; [[self tableView] reloadData]; NSLog("This message appears immediately"); ... }]; NSLog("This message appears immediately"); } 

For some reason, the interface seems to freeze for 5 seconds before the table is actually updated / redrawn (note that I'm calling reloadData!). All my log messages are printed immediately, so I'm not sure what causes the interface to freeze.

+8
ios5 twitter
source share
1 answer

Everything,

So I figured it out (sort of). I think this has something to do with threads, I shouldn't have done any interface elements in this thread.

To fix this, I surrounded the table material with some sort of dispatch code:

 [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ ... });}]; 

You still need to understand what is happening here, but I hope this helps if someone comes across the same problem.

+16
source share

All Articles