iphone - Get notification when NSOperationQueue finishes all tasks -


NSOperationQueue is wait other operators , but I do not want to wait Synchronous for this. I want to hide the progress indicator in UI when qi is over.

What is the best way to accomplish this?

I can not send notifications from my NSOperation , because I do not know who will be the last, and [queue operation] is not yet empty (Or worse - repipulated) when the notification is received.

> Use KVO to inspect your queue property, then you can tell what your queue is [queue] collaboration count] == ​​0 Was completed by checking for.

In the file you are doing KVO from anywhere, announce a reference for this type ():

Fixed NSString * kQueueOperationsChanged = @ "kQueueOperationsChanged";

When you organize your queue, do this:

  [self.queue addObserver: Path to self: @ "Operation" option: 0 Reference: & amp; KQueueOperationsChanged];  

Then enter your in ValleForKeyPath :

  - (zero) Inspection valueforcover: (NSString *) The keypad object: (Id) object change: (nsDictionary *) reference references: (zeros *) reference {if (object == self key & amp; keypath, excelstostring: @ "operation"] and complex == & Amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; ############ @ "Queue has completed"); }} And {[Super Avonwolf Four Path: Object of the Keypath: Object Changes: Change Reference: Context]; }}  

(It is believed that your NSOperationQueue is in the property queue )

something But before your object completely deluxe (or when this queue stops caring for the state), you have to cancel the registration with KVO in this way:

  [self.queue removeObserver : Self forKeyPath: @ "Operations" Reference: & amp; Amp; Qiuopathy changed]; Appendix: iOS 4.0 has a  NSOperationQueue.operationCount  property, which corresponds to KVO according to the documents. This answer will still work in iOS 4.0, so it is still useful for previous compatibility. 


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -