开发者

How can i execute one by one statement after delaying some time in iphone?

I have a problem in iPhone programing.

In my app i want to execute one by one sta开发者_开发问答tement after delaying some time.

Example:

Label1.text =@"2";

Then after delaying some time i want execute:

Label2.text =@"3";

Then after delaying some time i want execute:

Label2.text =@"8";

Then after delaying some time i want execute:

Label2.text =@"6";


you can use something like this -

[self performSelector:@selector(yourMethod:) withObject:someObjectInstance afterDelay:2.0];


[self performSelector:@selector(updateText:) withObject:self afterDelay:yourDelay]; 

will help you


You are going to use something called an NSTimer like this:

[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(update:) userinfo:nil repeats:YES];

What this does call the update: method on the current object and send the timer object as a parameter. In this method you can update your label.


A simpler approach than NSTimer is to simply sleep between the calls. However, you don't want to lock up the main thread.

[NSThread sleepForTimeInterval:1.0];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜