【问题标题】:UIButton doesn't dispatch touch event after uitextview becomes first responderuitextview 成为第一响应者后,UIButton 不调度触摸事件
【发布时间】:2013-01-30 01:02:12
【问题描述】:

我有一个UITextView,它应该在控制器加载时成为第一响应者(显示键盘)。唯一的问题是,我“膨胀”了两个UIView,每个都包含一个UIButton。当UITextView 还不是第一响应者时,这些按钮上的触摸事件会起作用,但是在UITextView 成为第一响应者之后,UIButtons 不会响应任何点击事件..

当 textview 成为第一响应者时,如何确保按钮仍然有效?

【问题讨论】:

    标签: ios uibutton uitextview touch-event first-responder


    【解决方案1】:

    希望这对你有用。它确实对我有用..

    UIButtonIBAction 方法中检查您的文本字段是否是第一响应者。 如果是第一响应者,请辞职。 这将关闭键盘并执行按钮操作。

    -(IBAction)btn:(id)sender
     {
      if ([txt isFirstResponder]) 
       {
        [txt resignFirstResponder];
       }
     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"hi" message:@"Hello" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
     [alert show];
    }
    

    【讨论】:

    • 这不起作用,因为添加到按钮的 IBAction 根本没有被触发。它从来没有进入那种方法..
    • @SanderBruggeman:你能添加你的 IBAction 代码吗?因为它对我来说很好用。
    【解决方案2】:

    按照in this answer 的建议,将按钮初始化更改为惰性可能会解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 2012-11-12
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      相关资源
      最近更新 更多