我有一個標準的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
是的,我已經包括它 –