안녕하세요 저는 객관적으로 새로운 c입니다. 나는 아이폰 용 앱을 만들려고 노력 중이다. 내보기에 버튼이 있고 functionSound가 호출 된 클릭이 있습니다. 이것은 제대로 작동하고 있습니다. 그것은 내가 원하는 소리를 재생합니다. 이제 타이머에 문제가 있습니다. 같은 버튼을 클릭하면 타이머가 시작되고 타이머 값이 레이블에 표시됩니다. 아직 NSTimer 자체로는 분명하지 않습니다. 나는 내가 여기서 뭔가 잘못하고있는 것 같아. 누구든지 이걸 도와 줄 수 있어요.Iphone NSTimer Issue
-(IBAction)playSound { //:(int)reps
NSString *path = [[NSBundle mainBundle] pathForResource:@"chicken" ofType:@"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: path];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
theAudio.delegate = self;
[theAudio play];
[self startTimer];
}
- (void)startTimer {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(targetMethod) userInfo:nil repeats:YES];
labelA.text = [NSString stringWithFormat:@"%d", timer];
}
위의 코드를 사용하면 버튼을 클릭하면 사운드가 재생되고 응용 프로그램이 닫힙니다.
감사 Zeeshan
THanks ole Begemann –