tags:

views:

23

answers:

1
+1  Q: 

Replacing NSTimer

Hi, using iphone sdk 4. I have an NSTimer that calls a method every 3 seconds, however the emethod being called is causing the UI to go unresponsive. I thought the NSTImer callback would happen in a separate thread to the main thread but it appears this is not so.

How can i replace this with an NSOperation or something so the method is still called every 3 seconds but in a background thread

A: 

Your current scenario: "X" method will be called by your time for every 3 seconds. ABC is the task you are performing in "X" method.

What you have to change: Create a new method "Y". Implement ABC task in "Y" method. In "X" method (comment all your code in X) and use [self performSelector:@selector(Y) withObject:nil]

Note that above selector works if "Y" method don't take any arguments.

Satyam svv
This won't change anything because Y will still be executed in the main thread. If you do it this way, you must use `performSelectorInBackground:withObject`.
Ole Begemann
You are wrong, when you call performSelector, it will be created in a new thread.
Satyam svv
No it will not. Only if you use `performSelector:onThread:withObject:waitUntilDone:` you may specify the thread the selector should be performed in, but that thread must already exist.
Toastor