Get the Indexpath from button action of one cell iOS swift
Solution:
If you had already added an action to one button or switch then you can easily get the indexPath for that button using the below function.Code
If you had already added an action to one button or switch then you can easily get the indexPath for that button using the below function.Code
extension UITableView {
func indexPathForView(view: AnyObject) -> NSIndexPath? {
let originInTableView = self.convert(CGPoint.zero, from: (view as! UIView))
return self.indexPathForRow(at: originInTableView) as! NSIndexPath
}
}
You can add the above extension for tableView and get the indexPath.You can call the function inside the button action like below.
@IBAction func didTapOnSwitch(_ sender: AnyObject) {
let swit = sender as! UISwitch
let index = self.myPlacesTbl.indexPathForView(view: swit)
}
Comments
Post a Comment