我想将输入附件视图添加到 UITextField ,而它是第一个响应者,即显示键盘。显然,在此状态下将 UIView 分配给 inputAccessoryView 属性不会显示此视图。我必须首先关闭键盘并重新选择 UITextField 。
I would like to add an input accessory view to a UITextField while it is the first responder, i.e. showing the keyboard. Apparently, assigning a UIView to the inputAccessoryView property in this state doesn't display this view. I have to first dismiss the keyboard and re-select the UITextField.
有没有办法添加输入附件视图没有解雇和重新选择?
Is there a way to add an input accessory view without dismissing and re-selecting?
推荐答案如果可能的话只分配 inputAccessoryView 一次。如果您需要进行自定义,并且只能确定在成为第一个响应者之前已经很晚,那么我仍然只会分配一次。但是在 UITextFieldDelegate 方法中自定义 inputAccessoryView 的子视图 textFieldShouldBeginEditing:。像这样:
If possible only assign the inputAccessoryView once. If you need it to be customized, and can only determine how very late just before becoming the first responder, then I would still only assign it once. But customize the subviews of the inputAccessoryView in the UITextFieldDelegate method textFieldShouldBeginEditing:. Like so:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { [self setupInputAccessoryViewForTextField:textField]; return YES; }更多推荐
键盘可见时,将输入附件视图添加到UITextField
发布评论