gpt4 book ai didi

ios - 不调用didSelectRowAtIndexPath获取UITableViewCell数据

转载 作者:行者123 更新时间:2023-11-30 13:20:25 24 4
gpt4 key购买 nike

我有一个UITableView,每个单元格都与一个文件关联。我使用自定义表格 View 单元格来显示文件标题,每个单元格都有一个编辑 UIButton,该按钮应该连接到另一个允许用户编辑文件标题的 View Controller 。我的问题是,当我点击编辑按钮时,我不确定如何将与单元格关联的文件数据发送到下一个 View Controller ,因为 didSelectRowAtIndexPath 没有被调用。

struct Files {
var title: String?
var username: String?
var url: String?
var fileId: Int?
var userId: Int?
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = self.fileTable.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! FileCell

let file = self.tableFiles[indexPath.row]
cell.fileLabel.text = file.title
cell.userLabel.text = file.username

cell.editButton.addTarget(self, action:#selector(HomeController.editPressed), forControlEvents: UIControlEvents.TouchUpInside)

return cell
}

func editPressed() {

self.performSegueWithIdentifier("HomeToEdit", sender: nil)

}

最佳答案

将 editPressed 更改为:

func editPressed(sender: UIButton!) {...}

当选择器添加为目标时,您需要将 : 添加到选择器

您可以通过调用sender.superView找到按钮的父单元格。将其转换为 FileCell,然后您可以访问它的 fileLabel.text(如果足够的话)。如果没有,您可以通过调用 indexPathForCell 找到单元格的索引。

关于ios - 不调用didSelectRowAtIndexPath获取UITableViewCell数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37820795/

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