There are many structures to download data from server. like
Another way is
Another way is
Make a file to set connection, and make another file to manage parser
ViewController =====================>> URLConnection
Delegate of URLConnectionfile =====================>> ViewController
then, in this delegate, NSData which is downloaded from server is further send to Parser class
ViewController =======================>> ParserClass
Delegate of Parser gives Array to ================= ViewController
then display that Array
Another way is to use thread
Call such methods in
[self performSelectorInBackground:@selector(doSomething) withObject:nil];
then in doSomething , call your connection file
Can anyone define the best way to download and save in a very organised and proper way, so that it becomes easy to manage and no hang of View occur.
Don't operate your downloading and parsing code on main thread. That is the only way to avoid UI freezes.
Recommended ways,
NSOperation
and NSOperationQueue
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,
NSOperation
and NSOperationQueue
(you can use GCD or other framework). Any view controller making call to the WS will talk to this class.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.