aschuch / StatefulViewController

Placeholder views based on content, loading, error or empty states
MIT License
2.14k stars 149 forks source link

UIView that conforms StatefulViewController protocol cannot be destroyed #71

Open YK-Unit opened 5 years ago

YK-Unit commented 5 years ago

UIView that conforms StatefulViewController protocol does not be destroyed.

Here is a StatefulViewControllerDemo.zip to illustrate this issue.

PS: the core code

class StateView: UIView, StatefulViewController {

    public var defaultLoadingView: UIView? {
        let defaultView = UIView()
        defaultView.backgroundColor = UIColor.white

        let label = UILabel()
        label.textColor = UIColor.blue
        label.text = "loading..."
        defaultView.addSubview(label)
        label.snp.makeConstraints { (maker) in
            maker.height.equalTo(20)
            maker.centerX.equalToSuperview()
            maker.top.equalToSuperview().offset(160)
        }
        return defaultView
    }

    public var defaultEmptyView: UIView? {
        let defaultView = UIView()
        defaultView.backgroundColor = UIColor.white

        let label = UILabel()
        label.textColor = UIColor.blue
        label.text = "no content"
        defaultView.addSubview(label)
        label.snp.makeConstraints { (maker) in
            maker.height.equalTo(20)
            maker.centerX.equalToSuperview()
            maker.top.equalToSuperview().offset(160)
        }
        return defaultView
    }

    override init(frame: CGRect) {
        super.init(frame: frame)

        loadingView = defaultLoadingView
        emptyView = defaultEmptyView
        setupInitialViewState()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // FIXME: StateView cannot be destroyed
    deinit {
        print("StateView deinit ...")
    }

    func hasContent() -> Bool {
        return false
    }

}
tungdx commented 5 years ago

Same issue, have you managed to solve it? @YK-Unit

YK-Unit commented 5 years ago

Same issue, have you managed to solve it? @YK-Unit

Yes, I just solve it now. And I have crated a PR #73. What's more, you can use the StatefulViewControllerDemo_v2.0.0.zip to verify it.