0
嗨,我是新的目标C。我正在尝试为iPhone制作应用程序。我的视图上有一个按钮,并且点击了playSound函数。这工作正常。它确实播放我想要的声音。 现在的问题是与计时器。我希望计时器在点击同一个按钮时开始,计时器值将显示在标签中。我还不清楚NSTimer本身。我想我在这里做错了事。谁能帮我这个。Iphone NSTimer问题
-(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
感谢OLE Begemann – 2009-11-14 04:33:18