Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nightwar00

macrumors newbie
Original poster
Jun 14, 2009
16
0
Hi all,
I have a little problem. I need to pause my program for 2 seconds.
But when i use : [NSThread sleepForTimeInterval:2]; the actions beforedon't work :
Code:
// some actions (1)
[NSThread sleepForTimeInterval:2];
//some action (2)

the actions(1) work after the pause i don't know why ??. the behaviour of the application is :

Code:
[NSThread sleepForTimeInterval:2];
//some actions(1)
//some actions (2)

how can i have the first behaviour?

thanks to any answer...
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
What are these "actions"? Some of them may not happen until the next run loop interation which won't happen until the thread wakes up.
 

nightwar00

macrumors newbie
Original poster
Jun 14, 2009
16
0
the actions are actually the following :
-display a UITextView
-perform an animation

how can i display the UITextView ("loading") and pause the system 2s and then remove the UITextView ??
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Sounds like you're simulating an actual loading process? Why?

I don't think there's a direct way to force the UI to refresh. On Mac OS X you can but the equivalent method in UIKit is gone.

You might be able to simulate this by using a timer and UIApplication's beginIgnoringInteractionEvents and endIgnoringInteractionEvents methods, but that's just from a quick glance at the docs.
 

nightwar00

macrumors newbie
Original poster
Jun 14, 2009
16
0
yes i want a loading process but not at the begining of the application.
i need to pause the application for 2s because another thread need to read a value before the actions (2) in my code below.

i juste want to tell the user to wait by the text "loading" and freeze the system for 2seconds...
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Sleeping like this is a bad idea. If you are using a sleep time for thread synchronization that is also a bad idea. Instead you should use some kind of correct thread synchronization or you should use a performSeledtor:withObject:afterDelay, or an NSTimer.

You could push a modal view controller and pop it when required.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.