0

每当“_currentField”(这是一个带有数字格式化程序的文本字段)的值大于或等于 1000 时,我希望“_congrats”(这是一个面板)显示出来,当它小于 1000 时,我想要“_errormsg”(另一个面板)显示。每次我输入任何值时,唯一弹出的是“_errormsg”。我究竟做错了什么?

- (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];

        }

    }
4

1 回答 1

0

由于您使用的是格式化程序,因此您需要让格式化程序解析该值。

(继承自)的formatter方法返回格式化程序对象。的方法返回适当的数值。NSCellNSTextFieldCellnumberFromString:NSNumberFormatter

在这种情况下,将文本字段的字符串值传递给格式化程序numberFromString:,您应该会看到像1,000变成1000(作为整数)这样的东西。

于 2012-07-15T21:41:55.390 回答