Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tikejc opened this issue Oct 9, 2023 · 0 comments
Open

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

tikejc opened this issue Oct 9, 2023 · 0 comments

Comments

@tikejc
Copy link

tikejc commented Oct 9, 2023

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()
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant