Is there a way to write NSTimer so that it just pauses the program for a second?

Trying to change the pic button, wait a second, and then go back. Not having much luck trying to get this to work, is there a way to just pause the program for a second, without a timer actually executing anything, and without executing a program with code?

+3
source share
2 answers

Try putting the change code in a method and call the change method:

[self performSelector:@selector(changeBack:) withObject:nil afterDelay:1.0];
+4
source

You may call

// sleep first appeared in Version 7 UNIX, 1979
sleep(1);

Or, more modern:

// usleep appeared in 4.3 BSD, released 1986
usleep(1000000);

Or, more modenly again:

// nanosleep can be found in POSIX.1b, published 1993
struct timespec ts;
ts.tv_sec = 1;
nanosleep(&ts, NULL);

Or, more modern and more Cocoa -y:

// +sleepForTimeInterval first appeared in Mac OS X 10.5, 2007
[NSThread sleepForTimeInterval:1.0];

. , , . .

NSObject Selector: withObject: afterDelay:. , . , , , , .. ..

, , ( , ).

+1

Source: https://habr.com/ru/post/1746162/


All Articles