开发者

iOS Reset/Restart Application from UIButton

开发者 https://www.devze.com 2023-04-05 02:07 出处:网络
I have a simple iOS app that I am developing that needs to be \"restarted\" or \"reset\" after a user performs a certain touch action and a \"reset\" button appears. The workflow of the app goes somet

I have a simple iOS app that I am developing that needs to be "restarted" or "reset" after a user performs a certain touch action and a "reset" button appears. The workflow of the app goes something like this:

  1. User holds a开发者_如何学Go certain area of the screen
  2. User lets go of the screen and quickly touches another area
  3. The time it took for them to let go and touch the next area is displayed in a UILabel.
  4. A reset button appears in which the user presses to try again.

Steps 1-3 work perfectly, but currently the only way I have to "reset" the app is to exit with the home button, open the multi-tasking menu and manually close it and re-open it.

I know this has to be able to be done as I 've seen it in many apps. I just can't find much help with the developer docs on it.

Thanks!


You can kill the app with a call to abort(). There's no way to start it after you killed it, though.

Perhaps you can schedule a local notification before killing the app that prompts the user to open it again.


You should probably just create a method that resets all of your variables and then calls the methods that begin steps 1-3. To have the button appear, make a UIButton IBOutlet to attach to the reset button, and then hide it in viewWillAppear like this:

[myButton setHidden:true];

To then show the button later, use the same button but set the value to false instead of true.


You could try removing your view controller from the application window and releasing it then instantiating a new instance of that view controller and adding the new instance to the window as the root view controller.

Since I'm assuming your view controller is where most of your "setup" code for your app is occurring this should effectively reset the app without having to write a lot of extra code. In addition, having the ability to instantiate a new instance of your view controller class is kinda the point of having it to begin with.


You can sleep your application for specified time interval.

+ (void)sleepForTimeInterval:(NSTimeInterval)ti

or

+ (void)sleepUntilDate:(NSDate *)aDate

Methods is works for you

Please refer NSThread class Documentation

0

精彩评论

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