Button in UITableViewCell not responding under ios 7

前端 未结 23 1708
刺人心
刺人心 2020-11-30 01:16

I have one tableview and each cell contains one button. It\'s working pretty well all iOS versions but 7. I don\'t know what\'s going on. The cell is constructed in one xib

相关标签:
23条回答
  • 2020-11-30 01:41

    When you are using Interface Builder (Storyboard) then be sure to check the User Interaction Enabled checkbox from the Content View

    0 讨论(0)
  • 2020-11-30 01:41

    I had transparent view on that cell which implemented some internal features and handled on touches on self.

    0 讨论(0)
  • 2020-11-30 01:43

    My problem was that I was adding UIButton as subview of UIImageView which has user interaction disabled by default. So I had to enable it:

    imageView.isUserInteractionEnabled = true
    
    0 讨论(0)
  • 2020-11-30 01:44

    I have also struggled with this problem and I did a lot of research over the different answers on stackoverflow and internet, the solution is different depending on the source of the problem. For the most case, you need to do the following with the element that is supposed to take user action (tap/click etc.):
    myButton.userInteractionEnabled = YES;

    Particularly for UILabel/UIImageView, by default the userInteractionEnabled flag is NO.

    If you are loading the view from a xib, you need make sure, from the custom cell view, content view, and the element you want the user action enabled, all have the check box checked:
    enter image description here

    In the example above, DeviceViewCell, Content View and Button element all have "User Interaction Enabled" check box checked.
    If the custom cell is implemented as a sub class of UITableViewCell, and the custom cell view is loaded from another xib file dynamically, you HAVE TO DO one more thing which is confusing to most of the people but I will explain why later on:
    In the custom cell's initialization method, you need to do the following:
    self.contentView.userInteractionEnabled = NO

    where self is the subclass of UITableViewCell you created. Again, IF the custom cell is implemented as a sub class of UITableViewCell, and the custom cell view is loaded from another xib file DYNAMICALLY, you need to do the above. Here is the explanation:

    self.contentView is NOT the same Content View you see in Interface Builder, it is created by the system as the default content view that is on TOP of every other views/elements within your custom cell view, and it obscures the rest of views in the view hierarchy. Hence, you will need to disable the user interaction for it before the UI elements in the custom cell view can receive user interaction events. Hope this helps. If you have a better explanation I would love to hear it :-). Again is is my observation and there could be other reasons. Discussion is welcome!

    0 讨论(0)
  • 2020-11-30 01:44

    The most obvious mistake I haven't seen described here is that you MUST have a selectedBackgroundImage for a UIButton to look different when selected. These are not like, say, UITableViewCells.

    myButton.setBackgroundImage(UIImage(named: "ButtonBackgroundSelected.png"), forState: .Highlighted)
    
    0 讨论(0)
  • 2020-11-30 01:44

    Okay, I've found a solution to this issue, but it appears to be a huge hack; however, it is all I was able to come up with (nothing else here worked for me).

    Overtop of my button I've added a UITextField which delegates to the table view cell in question. That tableViewCell instance implements -(BOOL) textFieldShouldBeginEditing:(UITextField *)textField and returns NO.

    0 讨论(0)
提交回复
热议问题