我有两个TextFields.一个只接受数值和其他十六进制值.我使用NSNumberformatter设置仅数字输入,如:
NSNumberFormatter *formatter; formatter = [[[NSNumberFormatter alloc] init] autorelease]; [formatter setNumberStyle:NSNumberFormatterNoStyle];
然后将其应用于TextField.
我该怎么做但只接受十六进制值?十六进制我的意思是1234567890ABCDEF.
或者,如果无法完成,如何检查该TextField上的文本是否为十六进制?
谢谢
解决方法
See this answer for a much better explanation,但它会是这样的:
- (void)controlTextDidChange:(NSNotification *)aNotification { NSError *outError; NSControl *textField = [aNotification object]; NSString *myText = [textField stringValue]; // check if myText is 0-9 or a-f,do something with it if its not hex. // update the NSNextField with the validated text [postingObject setStringValue:myText]; }