我已将 TextField 添加到 UICell 以允许用户更改所述单元格的 TextLabel。一切正常,键盘出现,当我按下回车键时 TextLabel 更改为正确的值。但是,我无法看到正在编辑的文本。这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
UITableViewCell *aCell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *aCategory = aCell.textLabel.text;
[[aCell detailTextLabel] setText:aCategory];
[aCell setEditing:YES animated:YES];
UITextField *userText =[[UITextField alloc] init];
userText.tag = indexPath.row;
[aCell addSubview:userText];
NSArray *test =[aCell subviews];
NSLog(@"I have %d many subviews",[test count]);
userText.alpha=1.0;
[userText setDelegate:self];
userText.autocorrectionType = UITextAutocorrectionTypeNo;
[aCell bringSubviewToFront:userText];
[userText becomeFirstResponder];
}
如果可能的话,我想在没有自定义单元格的情况下做到这一点。提前致谢。