Lab 8 - Multithreading

Objectives

You will extend your lab7 project to include multithreading to avoid hangs when performing Twitter API requests. 

  1. Modify your PersonListViewController so that the fetchInfoForUsername is done in a separate thread.  Create a method -loadPeople that does the Twitter API request.  Then in  -viewWillAppear include the code which creates the operation and adds it to an operationQueue.  After the thread is finished executing you will need to have the tableView reload the data so that it is displayed.  This can be done with [self.tableView reloadData].   Make sure that you only to the loading if that information hasn't previously been loaded.  You don't want to do extra work!
     
  2. You will want to give the user a visual clue that data is being loaded from an external location.  You can add a spinner (UIActivityIndicatorView) which will spin during the load.  Before adding the operation to the operationQueue you can invoke a method -showLoadingIndicators and after the loading is complete you can invoke a method -hideLoadingIndicators.

    The method -showLoadingIndicators will instantiate a UIActivityIndicator object, animate it and then add it as a subview to the tableView with [self.tableView addSubview: spinner]. 

    You probably want to center the spinner in the center of the tableView frame.  The following code will compute the position of the spinner:

        static CGFloat bufferWidth = 8.0;
        CGFloat totatlWidth = spinner.frame.size.width + bufferWidth;
        CGRect spinnerFrame = spinner.frame;
        spinnerFrame.origin.x = (self.tableView.bounds.size.width - totalWidth) / 2.0;
        spinnerFrame.origin.y = (self.tableView.bounds.size.height - spinnerFrame.size.height) / 2.0;
        spinner.frame = spinnerFrame;

    The method -hideLoadingIndicators will stop the animation, remove the spinner from its superview with [spinner removeFromSuperview] and release the spinner object.
     
  3. Add multithreading to PersonDetailViewController when the status values are fetched from the Twitter API.
     
  4. Compress your project and send it to me through the Dropbox in BlackBoard.