Mã của tôi:Làm thế nào để thêm trường văn bản để inputAccessoryView và làm cho TextView responder đầu tiên
- (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];
}
Tôi cố gắng thêm
[textField becomeFirstResponder]
ở cuối, nhưng nó không làm việc.
Một vấn đề khác mà phương thức ủy nhiệm để ẩn bàn phím khi ENTER được nhấn cũng không hoạt động.
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
thử UIView này * av = [[UIView alloc] initWithFrame: CGRectMake (0,0, 0,0, 320,0, 39,0)]; –
Xin lỗi tôi đã không đề cập rằng nó dành cho iPad và chế độ xem này trải dài dọc theo bàn phím, vì vậy chiều rộng không có ý nghĩa. – Michael