프로젝트에 구현하기 전에 타이머가있는 테스트 응용 프로그램을 만들었습니다. 타이머를 처음 사용했습니다. 그러나 문제는 [NSTimer timerWithTimeInterval: target: selector: userInfo: repeats: ];
을 사용하여 타이머를 구현했을 때 작동하지 않는 것입니다. 여기에 내 코드, 인터페이스입니다 :NSTimer timerWithTimeInterval : not working
@interface uialertViewController : UIViewController
{
NSTimer *timer;
}
-(void)displayAlert;
-(void)hideandview;
@end
구현 :
@implementation uialertViewController
- (void)viewDidLoad {
[self displayAlert];
[super viewDidLoad];
}
-(void)displayAlert{
timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(hideandview) userInfo:nil repeats:NO];
alert = [[UIAlertView alloc] initWithTitle:@"testing" message:@"hi hi hi" delegate:nil cancelButtonTitle:@"continue" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
}
-(void)hideandview{
NSLog(@"triggered");
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
[self displayAlert];
}
@end
가 그럼 난
[NSTimer scheduledTimerWithTimeInterval: target: selector:userInfo: repeats: ];
은, 그것은을 노력으로
[NSTimer timerWithTimeInterval: target: selector: userInfo: repeats: ];
를 변경가. timerWithTimeInterval:
의 문제점은 무엇인가요? 첫 번째 구현에서 어떤 변화가 있습니까? 미리 감사드립니다.
timerWithTimeInterval은 타이머를 생성하지만 시작하지 않으며 스케줄을 지정하지 않습니다. 나는 thats 유일한 차이라고 생각한다 – rooster117
@ rooster117 : 그렇다면 나는 타이머 발사 방법을 호출 할 필요가있다, 나는 정확하다? –
시작하려는 경우 scheduledTimerWithTimeInterval을 호출하십시오. 어느 쪽이든 – rooster117