I am using Xcode to create a Cocoa app for Mac OSX written in Objective-C.
Here is my code:
-(IBAction)clickToLaunchAppButtonClicked:(id)sender; {
//I want to hide the click to load app button
[clickToLoadButton setEnabled:NO];
[clickToLoadButton setHidden:YES];
//***I want to make the app wait for 1 second (This is where I'm stuck!)***
//I want to show the loading label
[loadingLabel setEnabled:YES];
[loadingLabel setHidden:NO];
//I want to show the loading progress bar and initialize it
[loadingProgressBar setHidden:NO];
[loadingProgressBar startAnimation:self];
//***I want to make the app wait for 3 seconds (Again, I don't know how to do this!)***
//I want to stop the loading progress bar animation
[loadingProgressBar stopAnimation:self];
//I want to hide the loading progress bar and loading label
[loadingLabel setHidden:YES];
[loadingLabel setEnabled:NO];
[loadingLabel setHidden:YES];
}
How can I make the app wait/pause for a few seconds? I tried the wait(), delay() or pause() functions, but they freeze the app, which is not what I want. Should I use an NSTimer? If so, please give me a simple way to implement it.
You can place the code you want to run on the 3 second delay in another method (delayedLoad) and use
performSelector: withObject: afterDelay:EDIT – spelling it out more in response to your comment
to create the other method, include this code in the same .m file (AppDelegate.m or similar)
And your existing method becomes
This is how you implement the 3 second delay. Hopefully you can extend this to implement the 1 second delay