Button in UITableViewCell not responding under ios 7

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

    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.

提交回复
热议问题