I am using tableview with multiple section and my data is structured like array of array form so I need to pass two integer values while tapping from button but we can pass only value with the help of tag property, so how would I solve my problem please help me out.
var data = [[String: Any]]()
self.data.append(["day": "Mon",
"record": [
["name": "Abhya", "status": false], ["name": "Anivesh" , "status": false]
]
])
self.data.append(["day": "Tue",
"record": [
["name": "Vivek" , "status": false], ["name": "Arun" , "status": false]
]
])
func numberOfSections(in tableView: UITableView) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: MyTableViewCell.identifier, for: indexPath) as! MyTableViewCell
let dictionary = self.data[indexPath.row]
let array = getArray(withDictionary: dictionary["record"])
let dict = array[indexPath.row]
cell.myLabel.text = dict["name"] as? String ?? ""
cell.tapButton.tag = indexPath.row
if dict["status"] as? Bool ?? false {
cell.tapButton.backgroundColor = .red
} else {
cell.tapButton.backgroundColor = .blue
}
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let dictionary = self.data[section]
let array = getArray(withDictionary: dictionary["record"])
return array.count
}
@IBAction func buttonTapAction(_ sender: UIButton) {
// want to cahnge the status false to true
}