【问题标题】:Function textFieldShouldBeginEditing is not called未调用函数 textFieldShouldBeginEditing
【发布时间】:2012-08-02 09:57:36
【问题描述】:

我知道有类似的问题,但这些答案对我没有帮助。我猜我还有其他错误。

我有一个textView,我将它的委托设置为self,但没有调用相关函数。

代码如下:

在.h中:

@interface MyViewController : UIViewController<UITextFieldDelegate>
@property (retain, nonatomic) IBOutlet UITextField *nameField;

在.m:

...
@synthesize nameField;
...
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    nameField.delegate = self;
...
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    exitKeyboardButton.hidden = NO;
    return YES;
}

【问题讨论】:

  • 你确定你已经在Interface Builder中连接了nameField插座吗?
  • 你工作正常,它没有连接,但它没有帮助。它仍然没有响应

标签: iphone objective-c cocoa-touch uitextview uitextfielddelegate


【解决方案1】:

我想你忘记了将文本字段的委托连接到你的 viewController。我经常忘记:)

【讨论】:

    【解决方案2】:

    试试这些:

    在viewDidLoad而不是viewWillAppear中设置委托(但正如idz所说,这有问题)

    尝试- (void)textFieldDidBeginEditing:(UITextField *)textField 而不是- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

    确保您在笔尖中连接了正确的名称

    【讨论】:

      【解决方案3】:

      最终我使用了相关的 IBAction 函数。 如果你有更好的想法,请告诉我,我会标记你的答案。

      【讨论】:

      • 你不需要设置顶部连接,一旦代理被编程或通过笔尖设置,所有的回调都会被固有地调用。例如,TableViewDelegate 调用 cellForRow、numberOfRows 等。您永远不必
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多