How to get class name of parent ViewController in Swift?

后端 未结 7 1915
清歌不尽
清歌不尽 2021-02-07 03:27

Is there any way to get class name of parent VC in present (child) UIViewController? My \'child\' VC (push) has two \'parent\'UIViewControllers, so I w

相关标签:
7条回答
  • 2021-02-07 04:10

    Add this extension and find parent view by it's type.

    extension UIResponder {
        
        func next<T: UIResponder>(_ type: T.Type) -> T? {
            return next as? T ?? next?.next(type)
        }
        
    }
    

    How to use

    self.next(UIViewController.self)
    
    0 讨论(0)
提交回复
热议问题