Я использую TableView с выбранной кнопкой, у меня проблема с кодом, потому что, когда кнопка выбрана, я не знаю, что такое IndexPath моей ячейки.
Я использую ячейку файла TableView с табличным представлением cell.xib
@IBOutlet weak var lbTitle: UILabel!
@IBOutlet weak var lbDetail: UILabel!
@IBOutlet weak var btnCheckMark: UIButton!
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
}
В моем контроллере View у меня есть это:
override func viewDidLoad() {
super.viewDidLoad()
self.topBar.rightBarButtonItem = UIBarButtonItem(title: "Apply", style: .done, target: self, action: #selector(self.apply))
self.topBar.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "backButton"), style: .done, target: self, action: #selector(backHome))
listeView.register(UINib.init(nibName: "TableViewCell", bundle: nil), forCellReuseIdentifier: "CheckList")
listeView.dataSource = self
listeView.delegate = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return deviceData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//let rowpath = indexPath.row
let cell = tableView.dequeueReusableCell(withIdentifier: "CheckList") as! TableViewCell
cell.lbTitle.text = "\(self.deviceData[indexPath.row].brandName) \(self.deviceData[indexPath.row].modelName)"
cell.lbDetail.text = "\(self.deviceData[indexPath.row].operatorName) \(self.deviceData[indexPath.row].version), \(self.deviceData[indexPath.row].browserName) \(self.deviceData[indexPath.row].version)"
//cell.selectionStyle = .none
cell.btnCheckMark.addTarget(self, action: #selector(checkMarkButton(sender:)), for: .touchUpInside)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
let test = TableViewCell()
test.lbTitle.text = "11"
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 71.0
}
@objc func checkMarkButton(sender: UIButton) {
if sender.isSelected {
sender.isSelected = false
nb -= 1
//rint(paramaters)
} else {
sender.isSelected = true
paramaters["devicesList[\(nb)][deviceId]"] = id
nb += 1
}
print(paramaters)
}
В моей функции checkMarkButton, яхочу знать indexPath.row