NSTimer
을 사용하지 않는 이유는 무엇입니까? 왜이 경우 GCD를 사용해야합니까? 또한,
- (void) showAlert:(NSTimer *) timer {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"title!"
message:@"message!"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
[alert release];
}
@PeyloW가 언급 한 바와 같이, 당신은 너무 performSelector:withObject:afterDelay:
를 사용할 수 있습니다 :
[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];
편집을 이제 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