こんにちは私は、私のcollectionview内のセルがタップされたときにポップアウトするViewControllerを持っています。私の問題は、ViewControllerの上部にあるボタンがタップされていることに応答していないことです。カスタムボタンがtouch-swiftに応答しない
ポップアウトビューコントローラのためのコード:
import UIKit
class PopUpCellViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var expandedNoteTable: UITableView = UITableView()
let cellId = "cellId"
var picture: UIImage?
var comment: UILabel?
let addNBackgroundView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(r: 244, g: 244, b: 255)
view.translatesAutoresizingMaskIntoConstraints = false
view.layer.cornerRadius = 8
view.layer.masksToBounds = true
return view
}()
lazy var addNButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Add N", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.isUserInteractionEnabled = true
button.setTitleColor(UIColor(r: 88, g: 88, b: 88), for: .normal)
button.titleLabel?.font = UIFont(name: "Nunito", size: 17)
button.addTarget(self, action: #selector(handleTouch), for: .touchUpInside)
return button
}()
let viewMBackgroundView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(r: 244, g: 244, b: 255)
view.translatesAutoresizingMaskIntoConstraints = false
view.layer.cornerRadius = 8
view.layer.masksToBounds = true
return view
}()
lazy var viewMButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("M", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitleColor(UIColor(r: 88, g: 88, b: 88), for: .normal)
button.titleLabel?.font = UIFont(name: "Nunito", size: 17)
button.isUserInteractionEnabled = true
button.addTarget(self, action: #selector(handleTouch), for: .touchUpInside)
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(viewMBackgroundView)
viewMBackgroundView.addSubview(viewMButton)
view.addSubview(addNBackgroundView)
addNBackgroundView.addSubview(addNButton)
view.addSubview(expandedNoteTable)
expandedNoteTable.frame = CGRect(x: 0, y: 67, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - (67+49))
expandedNoteTable.delegate = self
expandedNoteTable.dataSource = self
expandedNoteTable.separatorColor = UIColor.clear
expandedNoteTable.register(ExpandedNoteTableViewCell.self, forCellReuseIdentifier: "cellId")
self.view.backgroundColor = UIColor.white
setConstraints()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func handleTouch() {
print("button pressed")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId) as! ExpandedNoteTableViewCell
cell.imageView.image = picture
cell.commentLabel.text = comment?.text
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
let pictureHeight = picture?.cgImage?.height
return CGFloat(pictureHeight! + 1000)
}
func setConstraints() {
viewMBackgroundView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -25).isActive = true
viewMBackgroundView.topAnchor.constraint(equalTo: view.topAnchor, constant: ((self.navigationController?.navigationBar.frame.size.height)!/2)).isActive = true
viewMBackgroundView.heightAnchor.constraint(equalToConstant: 35).isActive = true
viewMBackgroundView.widthAnchor.constraint(equalToConstant: 90).isActive = true
viewMButton.centerXAnchor.constraint(equalTo: viewMBackgroundView.centerXAnchor, constant: 10).isActive = true
viewMButton.centerYAnchor.constraint(equalTo: viewMBackgroundView.centerYAnchor).isActive = true
addNBackgroundView.rightAnchor.constraint(equalTo: viewMBackgroundView.leftAnchor, constant: -15).isActive = true
addNBackgroundView.centerYAnchor.constraint(equalTo: viewMBackgroundView.centerYAnchor).isActive = true
addNBackgroundView.heightAnchor.constraint(equalToConstant: 35).isActive = true
addNBackgroundView.widthAnchor.constraint(equalToConstant: 95).isActive = true
addNButton.centerXAnchor.constraint(equalTo: addNBackgroundView.centerXAnchor).isActive = true
addNButton.centerYAnchor.constraint(equalTo: addNBackgroundView.centerYAnchor).isActive = true
}
}