У меня есть простой вид таблицы, с пользовательской ячейкой в нем, пользовательская ячейка имеет две кнопки (позже они будут использоваться как кнопки «Даун-голос» и «Вверх») есть ли способ передать значение indexPath.row на кнопку, чтобы определить, какая кнопка ячейки была нажата?Пропустить indexPath.row к кнопке в пользовательской ячейке с помощью SWIFT
TablewViewController.swift
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomTableViewCell
cell.piadaTitulo.text = "Lorem Ipsum"
cell.piadaDescription.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean commodo volutpat lectus, vitae semper tortor finibus at. Cras erat ligula, egestas sed tincidunt eget, condimentum maximus lectus. Aenean varius semper tellus, id congue lacus pretium a"
return cell
}
CustomTableViewCell.Swift
@IBOutlet weak var piadaTitulo: UILabel!
@IBOutlet weak var piadaDescription: UILabel!
@IBAction func piadaUpVote(sender: AnyObject) {
println("UPVOTE clicked")
}
@IBAction func piadaDownVote(sender: AnyObject) {
println("DOWNVOTE clicked")
}
можно присвоить 'tag' свойство в строке в функции 'cellForRowAtIndexPath'. Затем просто используйте sender.tag в 'IBAction', чтобы знать строку. – ad121
Я должен добавить тег в ячейку? например cell.tag = indexPath.row? –