gpt4 book ai didi

objective-c - 在 iOS 8 中向小键盘添加 'Done' 按钮时出错

转载 作者:行者123 更新时间:2023-12-03 20:51:03 25 4
gpt4 key购买 nike

因此,小键盘默认情况下没有“完成”按钮,因此我想添加一个。在 iOS 7 及更低版本中,有一些向键盘添加按钮的技巧,但它们似乎在 iOS 8 中不起作用。

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
if(textField.keyboardType == UIKeyboardTypeNumberPad){
textField.inputAccessoryView=self.toolBar; ///self.toolBar is a IBOutlet of UIToolBar and in this toolBar have a button 'Done'.

}

当运行此代码时,应用程序将终止并给出错误:

'UIViewControllerHierarchyInconsistency', reason: 'child view controller:
<UICompatibilityInputViewController: 0x7b283d20> should have parent view controller:
<HJ_PCreateUpdateCareTeamVC: 0x7a79bfc0> but requested parent is:
<UIInputWindowController: 0x7b9c9200>'

最佳答案

我做到了:

 textField = [[UITextField alloc]initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 44)];
textField.backgroundColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0];

[self.view addSubview:textField];
textField.keyboardType = UIKeyboardTypeNumberPad;


UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
UIBarButtonItem *doItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doDone)];
[toolBar setItems:@[doItem]];


textField.inputAccessoryView = toolBar;

///没问题

关于objective-c - 在 iOS 8 中向小键盘添加 'Done' 按钮时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26750907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com