Il mio codice:Come aggiungere campo di testo per inputAccessoryView e rendere il textView prima risponditore
- (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];
}
Ho provato ad aggiungere
[textField becomeFirstResponder]
alla fine, ma lo fa senza lavoro.
Un altro problema che delega il metodo per nascondere la tastiera quando si preme INVIO non funziona anche.
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
provare questo UIView * av = [[UIView alloc] initWithFrame: CGRectMake (0.0, 0.0, 320.0, 39.0)]; –
Mi spiace di non aver detto che è per iPad e questa vista si estende lungo la tastiera, quindi la larghezza non ha senso. – Michael