隐藏pkhud HUD在viewWillDissapear上不起作用

时间:2019-01-28 22:15:16

标签: ios swift uitabbarcontroller progress-bar viewwilldisappear

我根据需要在链中有几个api调用函数,显示了PKHUD hud窗口,hud效果很好,但是我无法将hud隐藏在viewWillDissapear中,要想表达更多的观点,我将profileViewController作为UINavigationController的一部分嵌套在viewBarBarcontroller中这样的层次结构。 enter image description here

在profileVC中,我有3个函数可以从APIrequest请求数据,每个函数都显示这样的外观。

    func loadData(){
        routeClient.instance.getProfile(success: {[weak self] data in
            guard let self = self else {return}
            do{
                let response = try JSONDecoder().decode(profile.self, 
                        if requestManager.instance.user.findHouse! == 0{
                            PKHUD.sharedHUD.contentView = PKHUDProgressView(title: "title", subtitle: "Subtitle")                                
                            PKHUD.sharedHUD.show()
                            self.loadHouse()
                        }else{                               
                            PKHUD.sharedHUD.contentView = PKHUDProgressView (title: "tittle", subtitle: "subtitle")
                            PKHUD.sharedHUD.show()
                            self.loadAnnounce()
                        }                       
                }
            }catch{
                print("error ocurrec in decoder \(error.localizedDescription)")
            }
        }, failure: {error in
            print("error in data load \(error.localizedDescription)")
        })
    }

然后在loadHouse中加载带有不同消息的公告功能。

func loadHouse(){
    routeClient.instance.getHouseByprofile(success:{[weak self] data in
        guard let self = self else {return}
        PKHUD.sharedHUD.contentView = PKHUDProgressView(title: "Procesando infromacion", subtitle: "")
        PKHUD.sharedHUD.show()
        if requestManager.instance.user.findHouse == 0{
            do{
                let response = try JSONDecoder().decode(houseModel.self, from: data)
                if response.id != nil {
                    self.house = response
                    PKHUD.sharedHUD.contentView = PKHUDSuccessView(title: "title", subtitle: "")
                    PKHUD.sharedHUD.show()
                    PKHUD.sharedHUD.hide(afterDelay: 1.5)
                    self.tableview.reloadData()
                }else{
                    print("the is is nil")
                    PKHUD.sharedHUD.contentView = PKHUDTextView(text: "subtitle")
                    PKHUD.sharedHUD.show()
                    PKHUD.sharedHUD.hide(afterDelay: 1.5)
                    self.tableview.reloadData()
                }
            }catch{
                print("error en la decodificacion \(error.localizedDescription)")
                PKHUD.sharedHUD.contentView = PKHUDErrorView(title: "title,", subtitle: "subtitle")
                PKHUD.sharedHUD.show()
                PKHUD.sharedHUD.hide(afterDelay: 1.5)
                self.tableview.reloadData()
            }
        }else{
            do{
                let response = try JSONDecoder().decode(houseResponse.self, from: data)
                PKHUD.sharedHUD.contentView =  PKHUDErrorView(title: "title", subtitle: "subtitle")
                PKHUD.sharedHUD.show()
                PKHUD.sharedHUD.hide(afterDelay: 1.5)
                self.tableview.reloadData()
            }catch{
                PKHUD.sharedHUD.contentView = PKHUDErrorView(title: "title,", subtitle: "subtitle")
                PKHUD.sharedHUD.show()
                PKHUD.sharedHUD.hide(afterDelay: 1.5)
            }
            self.tableview.reloadData()
        }
    }, failure: {[weak self] error in
        guard let self = self else {return}
        print(error.localizedDescription)
        self.tableview.reloadData()
    })
}
func loadAnnounce(){
    routeClient.instance.getAnnounceByProfile(success: {[weak self] data in
        guard let self = self else {return}
        do{
            let json = try JSONDecoder().decode(getAnnounceResponse.self, from: data)
            PKHUD.sharedHUD.hide()
            if json.success!{
                requestManager.instance.announce = (json.data?.count)! > 0 ? json.data![0] : nil
                self.tableview.reloadData()
            }
        }catch{
            PKHUD.sharedHUD.hide()
            print(error.localizedDescription)
        }
    }, failure: {error in
        PKHUD.sharedHUD.hide()
        print(error.localizedDescription)
    })
}

一切正常,应该做的是,我更改了tabbarcontroller中的选项卡,并且hud尚未在profileVC中显示,然后作为profileVC加载到显示的viewController中。 我试图隐藏HUD的内容如下。

override func viewWillDisappear(_ animated: Bool) {
    //PKHUD.sharedHUD.hide()
    print("va a desaparecer")
    PKHUD.sharedHUD.hide()
    NotificationCenter.default.removeObserver(self, name: .didchangeTab, object: nil)
    self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
    //self.navigationController?.navigationBar.barTintColor = .clear//UIColor.init(red: 106/255, green: 172/255, blue: 82/255, alpha: 1)
}
override func viewDidDisappear(_ animated: Bool) {
    PKHUD.sharedHUD.hide()
}

但没有任何效果,并且当tabBarController更改了tabbar项但向hud隐藏时,也向观察者添加了通知中心的通知,这仅在profileVC首次加载并且HUD现在显示时才发生,所以如果用户点击下一个选项卡项目,然后加载其他视图控制器,然后显示HUD。我还检查了内存泄漏,但没有粘合,即使执行了viewWillDissappear,为什么也没有从视图控制器的内存中释放内存。

0 个答案:

没有答案