Restrict NSTextField to only allow numbers
问题 How do I restrict a NSTextfield to allow only numbers/integers? I've found questions like this one, but they didn't help! 回答1: Try to make your own NSNumberFormatter subclass and check the input value in -isPartialStringValid:newEditingString:errorDescription: method. @interface OnlyIntegerValueFormatter : NSNumberFormatter @end @implementation OnlyIntegerValueFormatter - (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**