I have a custom class "TableViewCell" and "ViewController". I implemented func TapGestureRecognizer
in IBOutlet Label at "TableViewCell". Problem is in the func, there's a mainCounter
variable which counts how many times the label is tapped, and I'd like to get this value in "ViewController". I tried making TableViewCell's instance in ViewController and access it, but it's just a new instance so I could only get initial value 0. Can anyone give me even simple hint? here's two classes
'''
class TableViewCell: UITableViewCell {
@IBOutlet weak var showTimeLabel: UILabel!
var index = 0
var timeArr:[TimeStringLabel] = [TimeStringLabel]()
//******************************************
public var mainCounter:Int = 0
//******************************************
@objc func labelTapped(_ sender: UITapGestureRecognizer) {
if index >= timeArr.count {
}
else {
self.mainCounter = timeArr[index].timeCounter
index += 1
print(mainCounter) //In here, I can get values I want
}
}
func setupLabelTap() {
let labelTap = UITapGestureRecognizer(target: self, action: #selector(self.labelTapped(_:)))
self.showTimeLabel.isUserInteractionEnabled = true
self.showTimeLabel.addGestureRecognizer(labelTap)
}
'''
'''
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
var mainCounter:Int = 0
var tableViewCell = TableViewCell()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.tableView.delegate = self
self.tableView.dataSource = self
}
@IBAction func resetButton(_ sender: Any) {
print(tableViewCell.mainCounter) //In here, I can get only 0
}
'''