监听label
//. 协议<NSTextFiledDelegate>
- (void)controlTextDidChange:(NSNotification *)obj {
NSTextField *textFiled = obj.object;
int maxLimit = 16;
if ([[textFiled stringValue] length] > maxLimit) {
[textFiled setStringValue:[[textFiled stringValue] substringToIndex:maxLimit]];
}
}
与监听的具体内容相关:
// 限制0~999
- (void)myTextFieldCallBackWithTextFiled:(NSTextField *)textFiled {
NSRange range = [[textFiled currentEditor] selectedRange];
int iSel = (int)range.location;
NSString* strInput = [textFiled stringValue];
const char* acStr = [strInput UTF8String];
if (textFiled.stringValue.length > 3) {
[self textFieldNotAllowedInput:textFiled inString:textFiled.stringValue atIndex:iSel];
}
char cInputTmp = acStr[iSel -1];
if ( (cInputTmp < '0' || cInputTmp >