【发布时间】:2016-10-14 17:32:05
【问题描述】:
我经常遇到这个问题,我不知道如何将 UITableViewCells 视为 UIViews。
我在 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)
默认情况下,按钮在 UITableViewCells 上不会起作用,因为某种触摸手势值会覆盖新按钮。
我应该配置什么来防止这种覆盖?我希望用户触摸UITableViewCells 内的按钮。基本上,我的单元格需要表现得像 UIViews。
【问题讨论】:
-
你能看到
Join Channel的标题吗? -
尝试将 UITableViewCell 选择样式设置为 .None
-
UIButton 确实可以像 cell.accessoryView 一样正常工作
标签: ios uitableview