Background multithreading

Discussion in 'iOS Programming' started by mraheel, Mar 7, 2010.

  1. mraheel macrumors regular

    Joined:
    Apr 18, 2009
    #1
    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.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
  3. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #3
    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.
     
  4. mraheel thread starter macrumors regular

    Joined:
    Apr 18, 2009
    #4
    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
     

Share This Page