Featured post
iphone - Cocoa Touch - Display an Activity Indicator while loading a UITabBar View -
i have uitabbar application 2 views load large amounts of data web in "viewwillappear" methods. want show progress bar or activity indicator while data being retrieved, make sure user knows app isn't frozen.
i aware has been asked before. need clarification on seems rather good solution.
i have implimented code in example. question's original asker later solved problem, putting retrieval of data "thread". understand concept of threads, not know how impliment this.
with research, have found need move of heavy data retrieval background thread, of ui updating occurs in main thread.
if 1 kind provide example me, appreciative. can provide parts of existing code necessary.
if use nsurlconnection runs on thread automatically.
in viewdidload:
nsurlrequest *req = [nsurlrequest requestwithurl:theurl]; nsurlconnection *conn = [nsurlconnection connectionwithrequest:req delegate:self];
then need custom methods. if type in -connection
, press esc you'll see different methods can use. there 3 need this:
- (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response { // called when there response // if you're collecting data init nsmutabledata here } -(void) connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { // each time connection downloads // packet of data gets send here // can [mydata appenddata:data]; } - (void) connectiondidfinishloading:(nsurlconnection *)connection { // connection has finished can // want data here }
that there it. nsurlconnection handles multithreading , don't have worry. can create activity indicator , display , work because main thread empty. :)
- Get link
- X
- Other Apps
Comments
Post a Comment