我有一个 uiview,由顶部的地图视图和下面的 uitableview 组成。表格视图中有带有 uitextFields 的单元格和占位符。
当我编辑字段时,占位符会正确消失,但是如果我将 uitableviewcells 滚动到看不见的地方(即位于表格视图上方的地图视图的“后面”),占位符会与写入 uitextfield 的内容一起重新出现。
如果我用普通文本替换占位符,并清除 textFieldDidBeginEditing 上的文本,则会发生相同的重影效果。占位符文本和输入都显示。
我尝试在 textFieldDidBeginEditing 中将占位符和文本设置为零,但无济于事。
表格视图使用michaeltyson 的 TPKeyboardAvoidingTableView。
编辑 添加了我的 cellForRowAtIndex:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell%d", indexPath.row ]];
cell.textLabel.text = _tableData[indexPath.row];
if (indexPath.row == 0) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.delegate = self;
textField.placeholder = @"(Required)";
[cell.contentView addSubview:textField];
} else if (indexPath.row == 1) {
UILabel *textField = [[UILabel alloc] initWithFrame:CGRectMake(110, 6, 185, 30)];
textField.text = @"(Required)";
textField.textColor = [UIColor lightGrayColor];
textField.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:textField];
secondCellField = textField;
secondCell = cell;
} else if (indexPath.row == 2) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.delegate = self;
textField.placeholder = @"(Optional)";
[cell.contentView addSubview:textField];
} else if (indexPath.row == 3) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.delegate = self;
textField.placeholder = @"(Optional)";
[cell.contentView addSubview:textField];
} else if (indexPath.row == 4) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.delegate = self;
textField.placeholder = @"(Optional)";
[cell.contentView addSubview:textField];
} else if (indexPath.row == 5) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.delegate = self;
textField.placeholder = @"(Optional)";
[cell.contentView addSubview:textField];
} else if (indexPath.row == 6) {
UISwitch *textField = [[UISwitch alloc] initWithFrame:CGRectMake(210, 8, 50, 30)];
[textField addTarget:self action:@selector(segwayToWork) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:textField];
_workSwitch = textField;
}
return cell;