我有一个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/