不要在TableView中单击按钮

时间:2019-05-28 21:32:35

标签: ios swift

我已向tableview中添加了一个按钮,未单击按钮。未单击TableView顶部的按钮。我应该怎么做才能使按钮可点击?我需要使CircleMenu按钮可单击。该按钮现在位于tableView3的顶部。我需要将按钮添加到tableView吗?

override func viewDidLoad() {
        super.viewDidLoad()
        let button = CircleMenu(
                        frame: CGRect(x: view.frame.width/2 - 10, y: view.frame.height - 270, width: 50, height: 50),
                        normalIcon:"icon_menu",
                        selectedIcon:"icon_close",
                        buttonsCount: 3,
                        duration: 4,
                        distance: 85)
                    button.backgroundColor = UIColor.flatSkyBlue
                    button.delegate = self
                    button.layer.cornerRadius = button.frame.size.width / 2.0
                  view.addSubview(button)

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        if tableView == self.tableView1 {

        if !chipnumber2.text!.isEmpty {
            let cell:DeviceTableViewCell2 = tableView1.dequeueReusableCell(withIdentifier: cellIdNew, for: indexPath) as! DeviceTableViewCell2


            let deviceItem: Device3New = itemsNew[indexPath.row]

            let tap1 = UITapGestureRecognizer(target: self, action: #selector(tittleNewTapped(_:)))
            let tap2 = UITapGestureRecognizer(target: self, action: #selector(tittleNewTapped2(_:)))



                return cell
            }
        }

        if tableView == self.tableView2 {
            if !chipnumber.text!.isEmpty {
                let cell:DeviceTableViewCell2 = tableView2.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! DeviceTableViewCell2

                let deviceItem: Device3 = items[indexPath.row]



cell.backgroundColor = GradientColor(UIGradientStyle.leftToRight, frame: self.view.frame, colors: [UIColor.flatPowderBlueDark, UIColor.flatSand])
                return cell

            }

        }
        if tableView == self.tableView3 {
            if !chipnumber3.text!.isEmpty {
                let cell:DeviceTableViewCell2 = tableView3.dequeueReusableCell(withIdentifier: cellIdNew2, for: indexPath) as! DeviceTableViewCell2


                cell.backgroundColor = GradientColor(UIGradientStyle.leftToRight, frame: self.view.frame, colors: [UIColor.flatPowderBlueDark, UIColor.flatSand])
                return cell

            }

        }

        return UITableViewCell()

    }
}

1 个答案:

答案 0 :(得分:0)

只需将目标添加到按钮:

button.addTarget(self, action: #selector(buttonClicked(_:)), for: .touchUpInside)

然后是选择器方法:

@objc func buttonClicked(_ sender: UIButton) {
    print("clicked!")
}

(编辑:可能是duplicate吗?)