Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mraheel

macrumors regular
Original poster
Apr 18, 2009
136
0
Hi Guys,
I really couldnt understand much on multithreading. When you want things to be updated without the whole app getting stuck. A simple function to implement multithreading..

Code starts with Creating and Showing a "Loading.." View. And following by removing it after 2 seconds.
Meanwhile Im trying to query the SQL and add it to an array and reload the tableView.

How would I be able to do that.. using, i think "performSelector in Background" thread or something. I dont quite know how to implement the whole thing..


Code:
-(IBAction)showSearch:(id)sender{
LoadingView *loadingView = [LoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0] withMessage:@"Loading..."];
[loadingView
	 performSelector:@selector(removeView)
	 withObject:nil
	 afterDelay:2.0];
	
[appDelegate loadLabsOfCategory:CurrentTabSelected containingString:nil animated:YES];
[self.tableView reloadData];
}

any help is appreciated.. as always.
 
Instead of calling any UI method such as reloadData from a background thread, you should queue it up indirectly using performSelectorOnMainThread to pass the message to the main UI thread's run loop.
 
Okay, so, I will look into more tutorials. At the moment adding performSelectorOnMainThread for reloadData solves my issue? Any example of the sequence would be great.

But thanks guys, I'll look into that book
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.