Created
November 1, 2019 13:03
-
-
Save Xiangao2018/8a20524da735df9408a45eed18c2854a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITableView { | |
func indexPathForCellContainsView(_ view: UIView) -> IndexPath? { | |
guard let cell = view.ancestorOfType(UITableViewCell.self) as? UITableViewCell else { return nil } | |
return self.indexPath(for: cell) | |
} | |
} | |
extension UIView { | |
func ancestorOfType(_ t: AnyClass) -> UIView? { | |
if self.isKind(of: t) { | |
return self | |
} else { | |
return self.superview?.ancestorOfType(t) ?? nil | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment