I have this tableView:
but I can't recognize when user selects the UISwitch in the row. I know I need an @IBAction in the UITableViewCell class but I didn't found a guide that works for me. I'd like to print the indexPath of the row when user clicks on the UISwitch.
This is my class for cell:
class TicketsFilterCell: UITableViewCell {
@IBOutlet weak var textFilter: UILabel!
@IBOutlet weak var switchFilter: UISwitch!
class var reuseIdentifier: String? {
get {
return "TicketsFilterCell"
}
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
How can I do?
Thanks in advance.
Edit
My cellForRowAtIndexPath:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: TicketsFilterCell? = tableView.dequeueReusableCellWithIdentifier("cellTicketFilter", forIndexPath: indexPath) as? TicketsFilterCell
cell?.delegate = self
if(indexPath.section == 0) {
let text = status[indexPath.row]?.capitalizedString
cell?.textFilter.text = text
} else if(indexPath.section == 1) {
let text = queues [indexPath.row]?.capitalizedString
cell?.textFilter.text = text
} else if(indexPath.section == 2) {
let text = types[indexPath.row]?.capitalizedString
cell?.textFilter.text = text
} else if(indexPath.section == 3) {
let text = severities[indexPath.row]?.capitalizedString
cell?.textFilter.text = text
}
return cell!
}
IBAction
get thesuperview
of the sender (switch) which is the table view cell. Then get the index path. – vadian