ココアで特定の時間を待つためのより簡単な方法は、私が以下で思いついたものよりもありますか?
- (void) buttonPressed {
[self makeSomeChanges];
// give the user some visual feedback and wait a bit so he can see it
[self displayThoseChangesToTheUser];
[self performSelector:@selector(buttonPressedPart2:) withObject:nil afterDelay:0.35];
}
- (void) buttonPressedPart2: (id)unused {
[self automaticallyReturnToPreviousView];
}
明確にするために、このコードには機能上の問題はありません。私の唯一の牛肉は文体的なものです。私の場合、フローは機能するほど単純ですが、カプセル化するか、いくつかの条件をスローすると、状況が醜くなる可能性があります。この(架空の)例のようなコードで、待ってから同じポイントに戻る方法が見つからなかったのは、ちょっとしつこいことでした。
- (void) buttonPressed {
[self doStuff];
[UIMagicUnicorn waitForDuration:0.35];
[self doStuffAfterWaiting];
}