我有一个标准的UITextField,我已经添加到UITableViewCell中,每当我去编辑它时,其中的文本都不会清除。我曾尝试放置一个占位符,并且在编辑时也不会清除。这是怎么回事?iOS UITextField在编辑时不会清除
if (indexPath.row == 1) {
cell.textLabel.text = @"Device ID";
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
deviceID = [[UITextField alloc] initWithFrame:CGRectMake(115, 11, 388, 22)];
deviceID.delegate = self;
deviceID.adjustsFontSizeToFitWidth = YES;
deviceID.font = [UIFont boldSystemFontOfSize:15];
deviceID.textColor = [UIColor blackColor];
deviceID.autocorrectionType = UITextAutocorrectionTypeNo;
deviceID.autocapitalizationType = UITextAutocapitalizationTypeNone;
deviceID.textAlignment = NSTextAlignmentLeft;
deviceID.clearButtonMode = UITextFieldViewModeWhileEditing;
deviceID.keyboardType = UIKeyboardTypeDefault;
deviceID.backgroundColor = [UIColor clearColor];
deviceID.delegate = self;
deviceID.clearsOnBeginEditing = YES;
deviceID.text = [[NSUserDefaults standardUserDefaults] objectForKey:DEVICE_ID];
[deviceID setEnabled:YES];
[cell addSubview:deviceID];
}
- (BOOL)textFieldShouldClear:(UITextField *)textField {
return YES;
}
你已经包含了责任到ViewController你的界面中有'UITextFieldDelegate'协议吗? – sooper
是的,我已经包括它 –