我在使用 XIB 文件的单元格的 TableView 上遇到问题,当我第一次点击一个单元格时,它什么都不做,当我点击另一个单元格时,会调用 segue,但使用的数据是第一个细胞被窃听。我在“didDeselectRowAt”tableView 函数上使用“self.performSegue”。这是我的代码:
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
_ = tableView.dequeueReusableCell(withIdentifier: "CardCell") as! CardTableViewCell?
self.eachCard = cardsArray[indexPath.row]
self.performSegue(withIdentifier: "showCard", sender: tableView)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let card = segue.destination as? SingleShotViewController
if segue.identifier == "showCard" {
card?.name = eachCard["name"] as! String
card?.type = eachCard["type"] as! String
if eachCard["imageUrl"] == nil {
card?.imgURL = "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=264373&type=card"
} else {
card?.imgURL = eachCard["imageUrl"] as! String
}
}
}
最佳答案
使用这个重载代替 didDeselectRowAt
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
_ = tableView.dequeueReusableCell(withIdentifier: "CardCell") as! CardTableViewCell?
self.eachCard = cardsArray[indexPath.row]
self.performSegue(withIdentifier: "showCard", sender: tableView)
}
关于ios - Swift 4 UITableViewCell 第一次点击不调用 segue,第二次点击使用第一个单元格数据调用 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51792132/