开发者

how can I restart an application in iphone?

开发者 https://www.devze.com 2023-02-23 06:04 出处:网络
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 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.

  1. 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

  1. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消