【发布时间】:2021-05-07 01:52:35
【问题描述】:
我想在单击该特定 tableViewCell 时打印该按钮的文本。还要注意点击也会关闭视图。请帮我解决这个问题
以下是我尝试过的代码:
extension AlertViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return flags.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let flag = flags[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "FlagTableViewCell") as! FlagTableViewCell
cell.setUp(flag: flag)
//clickedFlagName = cell.flagNameLbl.text!
// print("Clickeeeeeeeeeeddddddd" + "\(clickedFlagName)")
clickedFlagName = cell.flagNameBtn.title(for: .normal)!
print("WhennnnClickeeeeeeeeeeddddddd " + "\(clickedFlagName)")
cell.flagNameBtn.addTarget(self, action: #selector(self.clickedFlagAction), for: .touchUpInside)
return cell
}
@objc func clickedFlagAction(_ sender: Any?) {
print("Tapped")
dismiss(animated: true)
}
}
【问题讨论】:
-
请勿发布代码图片。
标签: ios swift tableview swift5