计时器导致应用程序在某些情况下冻结
这是代码:
- (IBAction) startRecognition:(id)sender {
backgroundSoundLevel = [backgroundSoundChange stringValue];
timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
}
- (void)timerFired:(NSTimer*)theTimer
{
NSString *charlieSoundVolume = [charlieSoundLevel stringValue];
if ([charlieSoundVolume isLessThan: backgroundSoundLevel]) {
NSRunAlertPanel(@"", charlieSoundVolume, @"", @"", @"");
}
}
因此,当您按下“startRecognition”按钮时,它会启动此计时器循环“计时器已触发”。但是当 charlieSoundVolume 值小于backgroundSoundLevel 时,它会冻结应用程序。当它更大时,它工作得很好。所以这部分代码有问题。我不太确定是什么...
背景信息:charlieSoundVolume 是用 NSString 表示的当前音量。 backgroundSoundVolume 也用 NSString 表示。 charlieSoundVolume 是当前音量,backgroundSoundVolume 是由 NSSlider backGroundSoundChange 设置的预设音量。
有什么想法吗?
以利亚
Here is the code:
- (IBAction) startRecognition:(id)sender {
backgroundSoundLevel = [backgroundSoundChange stringValue];
timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
}
- (void)timerFired:(NSTimer*)theTimer
{
NSString *charlieSoundVolume = [charlieSoundLevel stringValue];
if ([charlieSoundVolume isLessThan: backgroundSoundLevel]) {
NSRunAlertPanel(@"", charlieSoundVolume, @"", @"", @"");
}
}
So when you press the button "startRecognition" then it starts this timer loop "timer fired". BUT when the value charlieSoundVolume is less than backgroundSoundLevel, it freezes the app. When it's greater, it works fine. So there's something wrong with that part of the code. I'm not really sure what...
Background info: charlieSoundVolume is the current volume expressed in an NSString. backgroundSoundVolume is also expressed in an NSString. The charlieSoundVolume is the current volume and the backgroundSoundVolume is the preset volume set by the NSSlider backGroundSoundChange.
Any ideas??
Elijah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是工作代码:
Here is the working code: