SWIFT 3 UIButton не запускаются в UITableViewCell

#swift #uitableview #uibutton

#swift #uitableview #uibutton

Вопрос:

У меня проблема с доступом к UIButton . Это UIButton находится внутри файла с именем UITableViewCell.xib

В этом файле есть UIButton , UILabel и UIImageView .

Я могу получить доступ к UIImageView и UILabel без проблем, но когда я пытаюсь добавить действие к UIButton , оно оказывается отключенным (когда я нажимаю на него, оно не мигает, как обычно).

Я использую следующий код для доступа к нему:

MainTableView

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


    let cell:mainTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! mainTableViewCell

    cell.contentView.isUserInteractionEnabled = true


    cell.openMenu.addTarget(self,action:#selector(testPressed), for:.touchUpInside)

    return cell
}


func testPressed()
{
    print("actionMenu")
}
  

MainTableViewCell.swift

 import UIKit

class mainTableViewCell: UITableViewCell {


    @IBOutlet weak var theImage: UIImageView!
    @IBOutlet weak var userName: UILabel!
    @IBOutlet weak var openMenu: UIButton!


    @IBOutlet weak var loadingBar: UIProgressView!


    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code

    }


    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
  

У кого-нибудь есть идея, как я могу решить эту проблему?

Спасибо

Комментарии:

1. При нажатии кнопки она перешла к функции testPressed?

2. вы уверены, что кнопка не отключена в конструкторе интерфейса?