我想用class
编写一个params
方法从viewController
删除navigation controller
,但我不知道如何处理它。
我的代码如下,我测试过,但没有成功:
class func removeVC(_ fromNav:UINavigationController, _ controller:UIViewController) {
let controllers:NSArray = fromNav.viewControllers as NSArray
for item in controllers {
if (item as AnyObject).isMember(of:controller) { // There is not pass by Xcode
// remove item out of fromNav.viewControllers
}
}
}
如何判断controller
的{{1}} class
等于controller
中的参数swift
?
答案 0 :(得分:0)
试试这个
方法1)
class func removeVC(fromNav: UINavigationController, controller: UIViewController) {
let controllers = fromNav.viewControllers
for item in controllers {
if item == controller {
fromNav.viewControllers.remove(at: fromNav.viewControllers.index(of: item)!)
}
}
}
用法:UtilSwift.navRemoveVC(self.navigationController!, self)
方法2):
class func navRemoveVC(_ fromNav:UINavigationController, withControllerClass:AnyClass) {
let controllers = fromNav.viewControllers
for item in controllers {
if (item as AnyObject).isKind(of: withControllerClass.self) {
fromNav.viewControllers.remove(at: fromNav.viewControllers.index(of: item)!)
}
}
}
用法:UtilSwift.navRemoveVC(self.navigationController!, withControllerClass:UserRegisterViewController.self)
答案 1 :(得分:0)
你可以试试这个:
if (item as AnyObject).isKind(of: UIViewController.self){
// remove item out of fromNav.viewControllers
}