【发布时间】:2013-07-09 23:51:11
【问题描述】:
我正在使用以下代码在 UITableView 单元格中创建文本字段:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
cell.showsReorderControl = YES;
}
if (indexPath.row == 1)
{
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(15,10,260,40)];
textField.placeholder = @"Activity 1: Type Name";
textField.delegate = self;
textField.clearButtonMode = YES;
[textField setReturnKeyType:UIReturnKeyDone];
[cell addSubview:textField];
}
return cell;
我正在以完全相同的方式创建 3 个文本字段。唯一的区别是 placeHolder 文本。
当键盘弹出时,视图向上滚动并且 textField 1 离开屏幕。返回后,我认为正在重新创建 textField。
以下是一些屏幕截图:
单元格第一次出现(看起来很棒):
滚动离开屏幕后返回(注意第一个文本字段):
在第一个单元格中,当我开始输入时,第二个创建的 textField 的 placeHolder 消失了,但第一个 textField 的占位符仍然存在:
两个问题:
- 如何避免在单元格中重新创建 textField?或消除这个问题?
- 重新创建后,为什么单元格 3 中的 textField 出现在单元格 1 的 textField 中,其 placeHolder 为“活动 3:类型名称”?
【问题讨论】:
-
不是3,是3和1重叠。这有什么建议吗?
标签: ios objective-c uitableview uitextfield