I have an timer in viewDidLoad, but I want to pass variable seconds assigned by slider, so what should I do for this for such implementation?
I think I have to restart app, so is there any other solution, or how can开发者_C百科 I restart my app?
a) Keep your timer as an instance variable in your appdelegate or somewhere else, and update its interval whenever the slider moves.
b) From the user's perspective you wouldn't want to restart the app for simple things such as these.
c) You can't restart an iPhone app or in any way play around with its lifecycle.
EDIT: If you are planning to have an instance of the timer available across the app, there are twp ways you can do that.
put is as an instance variable in the appdelegate class, the one which xcode would have created for you, with the projectnameAppDelegate. You will then be able to access it using
[UIApplication sharedApplication].delegate
from which you can get the instance of the NSTimer
- Or you can implement a common Singleton class, and put the timer in it. This is a much more accepted approach described here and scroll down to the bottom of the page.
For more info, search on ways to create a global object(although creating a global object is not a good idea), and follow the instructions.
精彩评论