NSThread sleep ?

Discussion in 'iOS Programming' started by nightwar00, Jul 9, 2009.

  1. nightwar00 macrumors newbie

    Joined:
    Jun 14, 2009
    #1
    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...
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. nightwar00 thread starter macrumors newbie

    Joined:
    Jun 14, 2009
    #3
    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 ??
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. nightwar00 thread starter macrumors newbie

    Joined:
    Jun 14, 2009
    #5
    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...
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    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.
     
  7. nightwar00 thread starter macrumors newbie

    Joined:
    Jun 14, 2009

Share This Page