Не нажимайте кнопку внутри в TableView - PullRequest
0 голосов
/ 29 мая 2019

Я добавил одну кнопку в 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 голосов
/ 29 мая 2019

Просто добавьте цель к кнопке:

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

А затем метод выбора:

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

(Изменить: возможно дублировать ?)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...