Button in UITableViewCell not responding under ios 7

前端 未结 23 1706
刺人心
刺人心 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:27

    The solution to this problem is;

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {    
    cell.bringSubviewToFront(cell.YOUR_UIView)    
    }
    

    This works for me.

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

    I faced a similar issue on both UITableViewCell and UICollectionViewCell. Few steps to follow:

    1. Always add subviews to content view of the cell view and NOT the cell view itself
    2. If you are adding a container view (which contains your button), disable the auto layout of the container view and enable the auto layout only for the contents inside the container view. Use frame layout for the container view.

    In short, TableView/CollectionView cells cannot take actionable subviews (UIButton, UISegmentedControl) that are auto-layout enabled. If you have a need for it, either disable auto-layouts and provide frames (or) put them inside a container view (Container view should have auto layout disabled) and add the actionable views (with auto layout) as subviews to the container view.

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

    I had subclassed UITableViewCell and solved it by changing this code:

    addSubview(myButton)
    

    to this:

    contentView.addSubview(myButton)
    

    in my UITableViewCell subclass.

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

    My Cell's outline

    In my case, everything that I would like the user to interact with is outside of the ContentView. Also I do not want the cell to be highlighted when it is selected.

    All labels (Name, Categories, etc.) are immediately under "Content View". The WebsiteButton is not under "Content View", but it is under "Local Directory Table Cell".

    In my tableViewController method tableView:cellForRowAtIndexPath: I have the following code: cell.contentView.userInteractionEnabled = NO;

    That is all and the user is able to interact with the button. I do NOT use [cell bringSubviewToFront:cell.websiteButton];

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

    Calling [cell bringSubviewToFront:button] after loading the cell from nib solved this for me.

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

    I have been get the same problem. The reason is

    self.contentView.Frame.size.height
    

    is always 44.

    There is a suggestion you can set your self.contentView.Frame to self.frame at the overwrite method - (void)layoutSubviews the problem will be solved

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