Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(iOS 5) when getting list of Twitter accounts, TableView hangs?

Tags:

twitter

ios5

I'm trying to get a list of twitter accounts to load up a UITableViewController that contains the data. I use 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 "hang" for 5 seconds before the table actually gets updated / redrawn (note that I AM calling reloadData!). All my log messages get printed right away, so I'm not sure what's causing the interface to freeze up.

like image 904
Michael D. Moffitt Avatar asked Nov 03 '11 06:11

Michael D. Moffitt


1 Answers

All,

So, I figured it out (sort of). I guess it has something to do with the threads, I wasn't supposed to do any UI stuff in that thread.

To fix it, I surrounded the table stuff with some dispatching code:

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

Still need to understand what's going on here, but hopefully this will help if someone runs into the same problem.

like image 111
Michael D. Moffitt Avatar answered Jan 02 '23 17:01

Michael D. Moffitt