【发布时间】:2018-04-18 15:36:16
【问题描述】:
以下代码,点击事件有效。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "SwiftCell")
let button = UIButton()
button.setTitle(hiddenGear ? "+" : "-", for: .normal)
button.setTitleColor(UIColor.lightGray, for: .normal)
button.addTarget(self, action:#selector(self.toggleGear), for: .touchUpInside)
button.frame = CGRect(x: self.view.frame.width - 36, y: 0, width: 30, height: 30)
button.backgroundColor = UIColor.red
cell.addSubview(button)
但我想要的是如下所示:
将UIButton移出uitableview单元格,点击事件不起作用。
button.frame = CGRect(x: self.view.frame.width - 36, y: -30, width: 30, height: 30)
尝试使用 cell.bringSubview(toFront: button) ,但它也不起作用。有什么想法吗?
【问题讨论】:
-
你在哪里添加这个代码???
-
@Sh_Khan 更新了我的问题
标签: swift uitableview uibutton swift4