-1

I have added one Button into tableview button is not clicked. The button is not clicked on the top of TableView. What should I do to make the button clickable? I need to make the CircleMenu button clickable. The button is now on top of tableView3. Do I need to add the button to the 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()

    }
}
Ilesh P
  • 3,940
  • 1
  • 24
  • 49
stakabekor
  • 453
  • 1
  • 6
  • 11

1 Answers1

0

Just add a target to the button:

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

And then a selector method:

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

(Edit: Possible duplicate?)

jake
  • 1,226
  • 8
  • 14