0

I'm constantly running into this issue, I don't know how to treat UITableViewCells as UIViews.

I added a button to my UITableViewCell:

    let btnWidth = self.contentView.frame.size.width * 1.1
    let btnHeight = self.contentView.frame.size.height * 1.6
    btnJoinChannel = UIButton(frame: CGRect(x:0,y:0,width:btnWidth,height:btnHeight))
    btnJoinChannel.setTitle("Join Channel", for: .normal)
    btnJoinChannel.setTitleColor(.white, for: .normal)
    btnJoinChannel.backgroundColor = .clear
    btnJoinChannel.addTarget(self, action: #selector(JRegionCell.loadRegion), for: .touchUpInside)
    self.contentView.addSubview(btnJoinChannel)

Buttons never work on UITableViewCells by default because some kind of touch gesture value overrides the new button.

What do I configure to prevent this override? I would like users to touch buttons inside UITableViewCells. Basically, my cells need to behave like UIViews.

Matt Andrzejczuk
  • 2,001
  • 9
  • 36
  • 51

1 Answers1

0

Your button is bigger than content view. Buttons don't work if they are out of superview.

Elto
  • 420
  • 3
  • 11