iphone - How to perform network task in background thread while updating UITableView? -


just trying figure out best way design such functionality? send asynchronous nsurlconnection hits server sends bunch of data. once data have perform work on pretty expensive , rather in bg thread prevent ui locking. lastly need have uitable update dynamically response server received , processed.

my question how go doing work in background thread as data arrives table doesnt wait until data has loaded before being updated??

this pseudo code have far. in viewcontroller have 2 bool flags newdatareceived , datafinisheddownloading. have 2 variables, string contains current data , nsarray kept results of processing data. then,

  1. in didreceiveresponse: spawn new thread calling performselectorinbackground: processing method selector.
  2. in method have loop first check newdatareceived see if new data has arrived , if work on it.
  3. once finished processing set nsarray results , call method updates table datasource , reloads table using performselectoronmainthread:
  4. lastly check datafinishedloading flag see if there more data process
  5. if there still data , start on again, otherwise cleanup thread , exit

also newdatareceived flag set in didreceivedata: actual data received. in didfinishloading set datafinishedloading flag signal data has been loaded.

i plan on using nslock's in #2-4 when checking status flags getting , setting received data string , results nsarray.

im sure there number of ways same thing seem way go it?

thx

you take @ nsoperation , nsoperationqueue. nsoperation perfect alternative doing heavy calculations , operations in background. if need continuously updates tableview implement protocol in operation handle callbacks tableview.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -