我目前正试图让这个工作。任何帮助表示赞赏。
我有一个UITableViewCell
有UITextField
内在的习惯。当我选择表格单元格时,我想做第UITextField
一个响应者。
但是 [textField becomeFirstResponder];
返回false。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
UITextField *textField;
for (UIView *view in [cell subviews]) {
if ([view isMemberOfClass:[UITextField class]]) {
textField = ((UITextField *)view);
}
}
[textField becomeFirstResponder];
}
根据要求,文本字段的初始化。这是在UITableViewCell
子类中完成的:
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Init Textfield
_textField = [[UITextField alloc] init];
_textField.backgroundColor = [UIColor clearColor];
_textField.delegate = self;
[self addSubview:_textField];
}
return self;
}