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 开发者_C百科([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
Here is the working code:
- (IBAction) startRecognition:(id)sender {
timer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
}
- (void)timerFired:(NSTimer*)theTimer
{
backgroundSoundLevel = [backgroundSoundChange stringValue];
NSString *charlieSoundVolume = [charlieSoundLevel stringValue];
if ([charlieSoundVolume isLessThan: backgroundSoundLevel]) {
NSRunAlertPanel(@"", charlieSoundVolume, @"", @"", @"");
}
}
精彩评论