像许多其他用户一样,我正在尝试将 UITextField 设置为 UITableViewCell 以用于编辑行。但我没有添加新视图,而是尝试使用附件视图属性。一开始我试过这个...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITextField *textField =[[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 44.0f)];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = textField;
[textField becomeFirstResponder];
}
...并且 UITextField 已正确添加,但我需要再次点击它才能显示键盘。但是,如果我这样做...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITextField *textField =[[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 44.0f)];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell addSubview:textField];
[textField becomeFirstResponder];
}
...它可以工作,键盘出现了,但是,我没有得到将它作为附件视图的任何其他好处(更容易定位,其他视图在它周围移动)。我想 addSubview: 调用正在改变响应者链或其他东西,并允许我的 UITextField 成为第一响应者,但认为也许有另一种方法可以让我设置单元格的附件视图。谢谢。