3

UIView のサブクラスでこれを行う場合:

[self performSelector:@selector(doSomething) withObject:nil afterDelay:5];

次に、次のようにキャンセルします(両方のバージョンを試しました):

 [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
 //[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];

「doSomething」メソッドは引き続き呼び出されます。私は何を間違っていますか?

4

1 に答える 1

1

NSObject クラス リファレンス:

cancelPreviousPerformRequestsWithTarget:selector:object:

以前に performSelector:withObject:afterDelay: に登録された実行要求をキャンセルします。

使用する:

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSomething) object:nil];

お役に立てれば。

于 2010-10-21T22:59:34.207 に答える