- (void)viewDidLoad {
[super viewDidLoad];
CGRect rectFake = CGRectZero;
UITextField *fakeField = [[UITextField alloc] initWithFrame:rectFake];
[self.view addSubview:fakeField];
UIView *av = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 39.0)];
av.backgroundColor = [UIColor darkGrayColor];
CGRect rect = CGRectMake(200.0, 4.0, 400.0, 31.0);
UITextField *textField = [[UITextField alloc] initWithFrame:rect];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:24.0];
textField.delegate = self;
[av addSubview:textField];
fakeField.inputAccessoryView = av;
[fakeField becomeFirstResponder];
}
He intentado añadir
[textField becomeFirstResponder]
al final, pero no realiza trabajo.
Otro problema que delega el método para ocultar el teclado cuando se presiona ENTRAR tampoco funciona.
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
probar esto UIView * av = [[UIView alloc] initWithFrame: CGRectMake (0.0, 0.0, 320.0, 39.0)]; –
Lo siento, no mencioné que es para iPad y esta vista se extiende a lo largo del teclado, por lo que el ancho no tiene sentido. – Michael