The code below correctly returns the cell:
func findSuperView(sender:UIButton!) -> UITableViewCell {
var superView : UIView? = sender.superview
var foundSuperView : UITableViewCell!
while superView != nil && foundSuperView == nil {
if let cell = superView as? UITableViewCell {
foundSuperView = cell
break
}
else {
superView = superView?.superview
}
}
return foundSuperView
}
But for finding indexpath in tableview it crashes:
var indexPath : NSIndexPath = self.table .indexPathForCell(findSuperView(sender))!
println("Section (indexPath)")
And I tried another way, but it was not successful:
var button : UIButton = sender as UIButton;
var touch: UITouch = events .allTouches()?.anyObject() as UITouch
var location : CGPoint = touch.locationInView(self.table)
var indexPath : NSIndexPath = self.table.indexPathForRowAtPoint(location)!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…