我有一个标准的 UITextField,已添加到 UITableViewCell 中,每当我去编辑它时,其中的文本都不会清除。我试过放置一个占位符,编辑时也不会清除。这是怎么回事?
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;
}