我目前正试图让这个工作.任何帮助表示赞赏.
我有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];
}
Run Code Online (Sandbox Code Playgroud)
根据要求,文本字段的初始化.这是在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 = …Run Code Online (Sandbox Code Playgroud)