My iPhone app has a sub view on its Welcome View Controller. The sub view parse data from a website and load data accordingly. Welcome View Controller has a continue button to go to the next view contro开发者_如何学Cller. But until the sub view load its data I cannot go to the next view controller.
Can anyone suggest me any solution on this. Thanks in Advance.
In you are using NSURLConnection
/NSURLRequest
to retrieve the data, I would suggest two approaches:
modify the code your class that retrieves the data so that the request is made asynchronous; this will make it non-blocking and the user will be able to move next without waiting; when moving next, you'll have the option of canceling the request, so to save bandwidth;
perform the request in a separate thread; you can do that either using
NSTask
or GCDdispatch_asinc
like shown below; in this case anyway, you have to be aware of the fact that your separate thread may not modify the UI (i.e., use UIKit), because this can only be done from the main thread. So, in your thread, you update the data, but then issue a refresh of the UI on the main thread (by usingperformSelectorOnMainThread
).dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{ [self SENDREQUEST]; });
As Vince pointed, you should retrieve the data from a separated thread (create a worker class to do that for you). When the classes finishes his job, you should tell the Welcome view, that the data is ready. You could achieve that, by using a protocol, or NSNotification.
精彩评论