我的代碼:如何將文本字段添加到inputAccessoryView,使TextView的第一個響應者
- (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];
}
我試圖在最後添加
[textField becomeFirstResponder]
,但它確實沒有工作。
另一個委託方法在按下ENTER按鈕時隱藏鍵盤的問題也不起作用。
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
試試這個UIView的* AV = [[UIView的頁頭] initWithFrame:方法CGRectMake( 0.0,0.0,320.0,39.0)]; –
對不起,我沒有提到它適用於iPad,並且此視圖沿着鍵盤延伸,所以寬度沒有意義。 – Michael