I'm developing an iOS app which includes a search form. When a user clicks search, I want to use an NSInvocationOperation (which is fine) to spawn another thread. On this thread, I'll call my data layer (a separate class) to retrieve data from a web service. Is there any way I can pass the data layer a method in my ViewController subclass which should be executed on completion, along with the other arguments (search term etc)? Kind of like .NET's BackgroundWorker?
Asked
Active
Viewed 430 times
1
-
What's wrong with just using a delegate and using that to inform your ViewController subclass that it has finished searching and then have your ViewController subclass do whatever code you want? – Nick Bull Jul 07 '11 at 13:02
1 Answers
2
Sounds like a case for Blocks (iOS4+). There's quite a nice tutorial here and excellent documentation from Apple here. Blocks are perfect when you want to kick off an asynchronous task and pass in details of what to do when it has finished, so could well be appropriate in your case.

Roger
- 15,793
- 4
- 51
- 73