下面的代码正确返回单元格:
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 }
但是为了在tableview中找到indexpath,它会崩溃:
var indexPath : NSIndexPath = self.table .indexPathForCell(findSuperView(sender))! println("Section (indexPath)")
我尝试了另一种方式,但没有成功:
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)!
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。