Whenever the value of “_currentField” (which is a text field with number formatter) is greater then or equal to 1000 I want “_congrats” (which is a panel) to show up and when its less than 1000 I want “_errormsg” (another panel) to show up. Every time I enter in any value the only thing that pops up is “_errormsg”. What am I doing wrong?
- (void)onTimer:(NSTimer*)aTimer {
if ([_currentField.stringValue integerValue] >= 1000)
{
[_congrats orderFront:(id)self];
[_progIndicator stopAnimation:(id)self];
}
else {
[_errormsg orderFront:(id)self];
[_progIndicator stopAnimation:(id)self];
}
}
Since you are using a formatter you need to ask the formatter to resolve the value.
The
formattermethod ofNSCell(thatNSTextFieldCellinherits from) returns the formatter object. ThenumberFromString:method of theNSNumberFormatterreturns the appropriate numerical value.In this case, pass in the string value of the text field to the formatter’s
numberFromString:and you should see things like1,000turn into1000(as an integer).