Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - another thread needs to send reloadData to the mainthread

I got a separate thread that creates a UIView object, inserts it into the UITableView's data source and then call reloadData on the UITableView. However, since it is a separate thread, it cannot call reloadData directly, it needs to make the mainthread do it... but how do you tell the mainthread to do it?

Thanks

like image 893
KaiserJohaan Avatar asked Oct 27 '11 09:10

KaiserJohaan


2 Answers

[self.tableView performSelectorOnMainThread:@selector(reloadData)
                                 withObject:nil
                              waitUntilDone:NO];
like image 133
Can Berk Güder Avatar answered Nov 05 '22 01:11

Can Berk Güder


You can use dispatch async, this method allows you to marshal worker thread to blocks of in-line code rather than methods using performSelectorOnMainThread:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableview reloadData];
});'
like image 39
RichIntellect Avatar answered Nov 04 '22 23:11

RichIntellect