Don't operate your downloading and parsing code on main thread. That is the only way to avoid UI freezes.
Recommended ways,
NSOperation
andNSOperationQueue
- GCD
- Use 3rd party frameworks like
AFNetworking
,MKNetworkKit
etc.
Also, if you have images in your table view, use technique called lazy loading.
I'd recommend not to use [self performSelectorInBackground:@selector(doSomething) withObject:nil];
. It gets messy if you don't know how to use, rather use GCD.
EDIT
Usually, what I follow,
- Webservice engine class which handles web service calls with
NSOperation
andNSOperationQueue
(you can use GCD or other framework). Any view controller making call to the WS will talk to this class. - Parser class will receive WS response from Webservice engine. It will parse response and create model class. On completion it will delegate parsed response to Webservice engine and from here it will be delegated to view controller.
- Error handling and progress indication is handled in Webservice engine.
- Important: Point where request is made from the view controller, the processing happens on background thread created by
NSOperationQueue
. Thus not freezing the UI.
Call to WS is initiated in viewDidLoad
, with progress indicator shown until process completes. But some times requirement is that the view controller is not created until WS response is downloaded. So choice to initiate request is based on your requirement.