なぜNSTimer
を使用しないのですか?この場合、なぜGCDを使用する必要がありますか? @PeyloWが述べたように、あなたもperformSelector:withObject:afterDelay:
を使用することができ、また
- (void) showAlert:(NSTimer *) timer {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"title!"
message:@"message!"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
[alert release];
}
:
[NSTimer scheduledTimerWithTimeInterval:5*60 target:self selector:@selector(showAlert:) userInfo:nil repeats:NO];
その後、同じクラス内で、あなたはこのような何かを持っていると思います
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"title!"
message:@"message!"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert performSelector:@selector(show) withObject:nil afterDelay:5*60];
[alert release];
EDIT GCDのdispatch_after
APIも使用できるようになりました:
double delayInSeconds = 5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title!"
message:@"message"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alertView show];
[alertView release]; //Obviously you should not call this if you're using ARC
});
私は興味をそそられていますが、30分から60分後にスレッドがどこで死ぬのですか? –
私はそれを読む場所を本当に見つけることができませんが、私はそう信じました。私は明日それをテストし、あなたに戻ってきます。 – Basel