根据验证(绑定)

时间:2015-07-29 18:46:35

标签: cocoa nstextfield

我有一个NSTextField,其绑定使用验证 - 如果值无效,则永远不会调用该集合;如果用户尝试使用无效值离开该字段,则应用程序会显示错误警报,其中包含2个选项(放弃或继续编辑),依此类推......

要获得更好的用户界面,我想在验证中更改文字颜色:

-(BOOL)validateMinValue:(id *)ioValue error:(NSError * __autoreleasing *)outError
{
    ParameterValue * param=*ioValue;
    if(*ioValue==nil || param.internalValue>_data->maxValue)
    {
        if (outError != NULL) {
            NSString *errorString = @"Minimum value must be less than the maximum value.";
            NSDictionary *userInfoDict = @{ NSLocalizedDescriptionKey : errorString };
            *outError = [[NSError alloc] initWithDomain:@"minValue-maxValue"
                                                   code:1
                                               userInfo:userInfoDict];
        }
        _minValueField.textColor=[NSColor redColor];
        return NO;
    }
    _minValueField.textColor=[NSColor whiteColor];
    return YES;
}

问题是,如果用户试图使用无效值离开该字段,并且他选择了" discard change"警报上的选项,该值被丢弃,但textcolor继续为红色(因为系统不会重新验证它知道的有效值)。 有什么建议吗?

0 个答案:

没有答案
相关问题