【问题标题】:equivalent to textViewShouldBeginEditing for TEXTFIELD?相当于 TEXTFIELD 的 textViewShouldBeginEditing?
【发布时间】:2011-04-23 19:41:31
【问题描述】:

我有一个 UITextView,如果用户触摸它,就会在键盘上添加一个辅助视图,以便用户可以再次隐藏键盘。

我现在添加了一个 UITextField,并且想知道如何在 UITextField 弹出后将相同的附件视图添加到键盘。 UITextfield 的以下代码是否有等价物? textFieldShouldBeginEditing 不存在...

 - (BOOL)textViewShouldBeginEditing:(UITextView *)aTextView {


    if (aTextView.inputAccessoryView == nil) {
        aTextView.inputAccessoryView = accessoryView;    
        self.accessoryView = nil; // After setting the accessory view for the text view, we no longer need a reference to the accessory view
    }

    return YES;
}

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitextfield


    【解决方案1】:

    有 UITextFieldDelegate 协议,你可以在其中找到方法

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    

    一直在寻找那个?

    【讨论】:

      【解决方案2】:

      It does exist,除非它在UITextFieldDelegate 协议中找到。

      如果您的视图控制器同时管理文本视图和文本字段,请让控制器类同时采用 UITextViewDelegateUITextFieldDelegate

      【讨论】:

        【解决方案3】:

        对于UITextField,您的代码必须如下。

        - (BOOL)textFieldShouldBeginEditing:(UITextField *)aTextField {
        
        
            if (aTextField .inputAccessoryView == nil) {
                aTextField .inputAccessoryView = accessoryView;    
                aTextField.accessoryView = nil; // After setting the accessory view for the text view, we no longer need a reference to the accessory view
            }
        
            return YES;
        }
        

        使用UITextFieldDelegate 协议确认UITextField

        【讨论】:

          猜你喜欢
          • 2020-03-10
          • 1970-01-01
          • 2018-10-21
          • 2013-07-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多