ios - Tearing down UITableViewDataSource -


in our application have several uitableviews have network-backed data sources can take time populate. here's typically happens:

  1. user triggers view.
  2. in viewdidload, view's datasource created.
  3. the model's -load method called
  4. the model issues network request data ...
  5. before request finishes, user backs out of view.
  6. the view's viewwilldisappear, viewdiddisappear, viewdidunload, , dealloc methods called.
  7. the request finishes. unfortunately, or part of table view gone, havoc ensues.

so, our solution has been "tear down" data source , cancel outstanding network requests doesn't happen. questions have are:

  1. what "proper" way tear down data source? you lose references it, , use -dealloc cancel outstanding network requests?

  2. where should tear down? in viewdidunload? dealloc?

  3. the same 2 questions apply model, actually: what's right way tear down? , when?

note doesn't apply network requests: have view uses geolocation, , time geolocation completion block called, view it's supposed update long gone.

thanks!

p.s. additional question:

  1. in case of uitableview, possible rows in view deallocated before uitableview's -dealloc called? if deallocated at, say, viewwilldisappear time, , request happens finish after that, before -dealloc, if request happens try , update uitableview rows, havoc ensue.

does make sense?

are using objective-c, c++, or objective-c++? ask because referring methods c++ syntax (::) instead of obj-c (-), , not c++ side.

usually implement -dealloc method if object has work when deallocated (torn down). in there cancel network requests , release low-level resources file handles. method called automatically obj-c runtime when there no more references instance , ready deallocate - should not call method manually.

the accepted pattern nil out strong references object when you're done , let runtime handle deallocating it. if follow pattern everywhere (networking, file system access, gps, etc) it's pretty easy work with.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -