gpt4 book ai didi

ios - 点击识别器仅在第一个单元格中工作

转载 作者:行者123 更新时间:2023-11-29 01:15:33 25 4
gpt4 key购买 nike

我有一个带有一个原型(prototype)单元格的 UITableView,我添加了一个长按手势识别器,它在代码中有一个 Action ,如下所示:

 @IBAction func Itinerario(sender: AnyObject) {

let a = self.tabla
let b: String = "\n"
let c: String = "\n"
let d: String = "*Lugar Destacado"
let sum = a + b + c + d

let alert = UIAlertController(title: "Itinerario de Procesión", message: "\(sum)", preferredStyle: UIAlertControllerStyle.Alert)
let action1 = UIAlertAction(title: "Atrás", style: UIAlertActionStyle.Cancel, handler: nil)

alert.addAction(action1)


self.presentViewController(alert, animated: true, completion: nil);



}

但是当我运行项目时,它只对表格的第一个单元格有效。我怎样才能让它适用于所有人?

最佳答案

检查控制台,相当确定您会看到 iOS 9 及更高版本的错误。将手势识别器从单元格移动到表格 View 并说:

@IBAction func Itinerario(sender: UITapGestureRecognizer) {
//if you need the cell or index path
let location = sender.locationInView(self.tableView)
let indexPath = self.tableView.indexPathForRowAtPoint(location)
let cell = self.tableView.cellForRowAtIndexPath(indexPath)
if indexPath != nil
{
let a = self.tabla
let b: String = "\n"
let c: String = "\n"
let d: String = "*Lugar Destacado"
let sum = a + b + c + d

let alert = UIAlertController(title: "Itinerario de Procesión", message: "\(sum)", preferredStyle: UIAlertControllerStyle.Alert)
let action1 = UIAlertAction(title: "Atrás", style: UIAlertActionStyle.Cancel, handler: nil)

alert.addAction(action1)


self.presentViewController(alert, animated: true, completion: nil);
}


}

关于ios - 点击识别器仅在第一个单元格中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35233178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com