Mac/iOS Xcode -- how to lauch a asynchrounous thread by pressing a button, but not locking up the button

Just started Xcode today and I was able to create two buttons and a UILabel and load the "app" to my iPad. When I press a button the label display a text "Hello" and when I press another button, the label text changed to "how are you?".

While that's cool, I wanted to be able to let the Label change the text every few seconds by itself, after I press a button and stop the flashing by pressing another button.  How can I do this?   I was trying something like this:

    button_pressed_function {   // excuse me, for being a C++ programmer for many years

         I = 0
        while(I < 8)
                label.text = "hello";
                label.text = "what's up?";

Apparently it didn't work though the while-loop did run and it freezed the button before it exits. It freezed for about 48 = 8x6  seconds and just showed  "what's up" in the label, never change the text during the loop run. I know this is certainly not the right way, because 1) even if did flip the text, it locks the button (is there a method of UIlabel to
reader the text in the middle for the loop?)   2)  It didn't even change the text.

I guess there should be a function to dispatch another thread for the while_loop in the background and release the button-pressed function so the button can pop back up. Please help, and sample code will be very appreciated.

Who is Participating?
pgnatyukConnect With a Mentor Commented:
Add [label setNeedsDisplay]; after label.text=...
It will update the GUI control on the screen.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.