I have some code where I have 3 buttons and I would like to find out the parent view of those buttons when clicked
@IBAction func resizeButtonClicked(sender: UIButton) {
if(sender.isEqual(resizeButton)) {
//This is to convert to small square
} else if(sender.isEqual(maximizeButton)) {
//This is to convert to maximized view
} else if(sender.isEqual(closeButton)) {
//This is to close the view completely
}
}
Now I can identify the sender button but how do I identify the view this button is sitting in?
Thank you
Nikhil
Please try the following
sender.superview
I you don't want to create a custom class and also don't want to use accessibilityHin:
func performAction(_ sender : AnyObject?)
{
let cell = sender?.superview??.superviewOfClassType(UITableViewCell.self) as! UITableViewCell
let tbl = cell.superviewOfClassType(UITableView.self) as! UITableView
let indexPath = tbl.indexPath(for: cell)
let myData = myDataArray[indexPath.row]
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With