rickytan / RTRootNavigationController

Implicitly make every view controller has its own navigation bar
MIT License
2.15k stars 379 forks source link

APP 里面创建了个单例ViewController,需要重复push这个页面 #197

Closed a1259667899 closed 6 years ago

a1259667899 commented 6 years ago

比如单例VC是S,一开始从A push到S,再从S push到B,然后再从B push到C,再从C push到S,这样正常的顺序应该是A,B,C,S,我的代码是这样的

 class func pushPlayViewControllerFromViewController(viewController:UIViewController){
        let vc = SLocalPlayViewController.sharedInstance
        var arr = viewController.navigationController?.viewControllers
        if (arr?.contains(vc))! {
            let index = arr?.index(of: vc)
            arr?.remove(at: index!)
            viewController.rt_navigationController?.viewControllers = arr!
        }
        vc.hidesBottomBarWhenPushed = true
        viewController.navigationController?.pushViewController(vc, animated: true)
    }

然后在A和B之间会出来一个空白的页面

rickytan commented 6 years ago

158 能不能解决你的问题?还在测试中

a1259667899 commented 6 years ago

我用这种方式获取nv的子视图

let arr = viewController.rt_navigationController?.viewControllers`
但是获取到的结果却是这样`po arr
▿ Optional<Array<UIViewController>>
  ▿ some : 4 elements
    - 0 : <RTContainerController: 0x11463b6e0>
    - 1 : <RTContainerController: 0x114954660>
    - 2 : <RTContainerController: 0x117250eb0>
    - 3 : <RTContainerController: 0x117750770>

怎样才能获取到我的ViewController类型呢

a1259667899 commented 6 years ago

找到一个讨巧的方法

class func pushPlayViewControllerFromViewController(viewController:UIViewController){
        let vc = SLocalPlayViewController.sharedInstance
        viewController.rt_navigationController.removeViewController(vc)
        vc.hidesBottomBarWhenPushed = true
        viewController.rt_navigationController.pushViewController(vc, animated: true)
    }

但是仍然不知道怎么获取到我自定义的ViewController类型,拿到的都是RTContainerController

rickytan commented 6 years ago

最新版直接用:

self.navigationController.viewControllers;

就可以拿到你的类型