Tencent / QMUI_iOS

QMUI iOS——致力于提高项目 UI 开发效率的解决方案
http://qmuiteam.com/ios
Other
7.11k stars 1.39k forks source link

QMUI 认为 popViewController 会成功,但实际上失败了 bug #1529

Open tikejc opened 1 year ago

tikejc commented 1 year ago

1、AppDelegate 导航页面初始化

window = UIWindow(frame: UIScreen.main.bounds)
window!.rootViewController = QMUINavigationController(rootViewController: TestA())
window!.makeKeyAndVisible()

2、问题场景:A页面导航到B页面,然后B页面模态 (present) 方式打开C页面,在C页面dismiss方式关闭,并立即navigationController?.popViewController(animated: true) B页面

3、然后触发QMUIKit断言错误:

QMUI 认为 popViewController 会成功,但实际上失败了 UINavigationController+QMUI.h文件 279行代码

4、QMUIKit版本号:4.7.0

5、赋完整代码:

// 第一个界面:TestA
class TestA: UIViewController {
    override func viewDidLoad() {
        view.backgroundColor = .white

        title = "页面A"

        let b = UIButton()
        b.frame = CGRect(x: 100, y: 100, width: 200, height: 40)
        b.layer.borderWidth = 1
        b.layer.borderColor = UIColor.black.cgColor
        b.clipsToBounds = true
        b.layer.cornerRadius = 5
        b.center = view.center
        b.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        b.setTitleColor(.black, for: .normal)
        b.setTitle("导航到B页面", for: .normal)

        view.addSubview(b)
    }

    // 点击按钮导航到TestB界面
    @objc func buttonClick() {
        let testB = TestB()
        self.navigationController?.pushViewController(testB, animated: true)
    }
}

// 第二个界面:TestB
class TestB: UIViewController, TestDelegate {
    override func viewDidLoad() {
        view.backgroundColor = .white

        title = "页面B"

        let b = UIButton()
        b.frame = CGRect(x: 100, y: 100, width: 300, height: 40)
        b.layer.borderWidth = 1
        b.layer.borderColor = UIColor.black.cgColor
        b.clipsToBounds = true
        b.layer.cornerRadius = 5
        b.center = view.center
        b.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        b.setTitleColor(.black, for: .normal)
        b.setTitle("present方法打开C页面", for: .normal)

        view.addSubview(b)
    }

    // 点击按钮
    @objc func buttonClick() {
        let testC = TestC()
        // 设置代理
        testC.delegate = self
        self.present(testC, animated: true)
        // self.navigationController?.pushViewController(testC, animated: true)
    }

    /// 代理方法
    func pageBack() {
        print("关闭界面TestB")
        // TODO: 这里会导致界面崩溃
        self.navigationController?.popViewController(animated: true)
    }
}

// 第三个界面:TestC
class TestC: UIViewController {

    weak open var delegate: TestDelegate?

    override func viewDidLoad() {
        view.backgroundColor = .white

        title = "页面C"

        let b = UIButton()
        b.frame = CGRect(x: 100, y: 100, width: 200, height: 40)
        b.layer.borderWidth = 1
        b.layer.borderColor = UIColor.black.cgColor
        b.clipsToBounds = true
        b.layer.cornerRadius = 5
        b.center = view.center
        b.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
        b.setTitleColor(.black, for: .normal)
        b.setTitle("关闭页面C", for: .normal)

        view.addSubview(b)
    }

    @objc func buttonClick() {
        self.dismiss(animated: true)
        // navigationController?.popViewController(animated: true)
        self.delegate?.pageBack()
    }
}

protocol TestDelegate: NSObjectProtocol {
    func pageBack()
}

请问这个问题如何修复啊????