1. 获取界面view controller
extension UIView {
//返回该view所在VC
func firstViewController() -> UIViewController? {
for view in sequence(first: self.superview, next: { $0?.superview }) {
if let responder = view?.next {
if responder.isKind(of: UIViewController.self){
return responder as? UIViewController
}
}
}
return nil
}
}
然后可以调用里面的函数啦, 赞
focus
2. cell获取view
extension UITableViewCell {
//返回cell所在的UITableView
func superTableView() -> UITableView? {
for view in sequence(first: self.superview, next: { $0?.superview }) {
if let tableView = view as? UITableView {
return tableView
}
}
return nil
}
}