Reputation: 10262
I have a UITableView where I download data from a remote server one by one when the cells appear.
Is it safe to create one NSOperationQueue per cell? I am worried that this may trigger thread explosion (if there are too many threads). Having NSOperationQueue per cell instance is easier for development, because once the cell gets reused, I can just cancel all operations on the NSOperationQueue.
In contrast, if I use one NSOperationQueue per UIViewController, then I can pass the NSOperationQueue to the cell, and the cell can add its NSOperation to that queue. But, I need to handle in some way such that I can cancel that operation when the cell gets reused (store reference to the NSOperation in a dictionary inside the UIViewController, etc.).
Most tutorials have one NSOperationQueue in the UIViewController, but I have seen one where he used one NSOperationQueue for each cell.
Upvotes: 1
Views: 73
Reputation: 13577
In given below tutorial provide the option for the cancel operation and also resume operation according to your requirement.
A good example from Ray Wenderlich : http://www.raywenderlich.com/19788
Update:
If you have use NSOperationQueue
in UITableView
then You need to manage properly. For example AFNetworking library have use NSOperationQueue
for image downloading from url and other task that's work fine. So my suggestion is if you want use NSOperationQueue
in UITableView
then manage it properly otherwise it definitely cause an issue in future to handle long data.
Upvotes: 0