【发布时间】:2011-11-12 04:04:39
【问题描述】:
我的代码:
- (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 alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 39.0)];
-
对不起,我没有提到它是用于 iPad 的,而且这个视图沿着键盘延伸,所以宽度没有意义。
标签: objective-c ios ipad uitextfield