在navigationBar中隐藏和显示后退按钮

时间:2015-05-18 12:54:36

标签: ios swift back-button navigationitem

我有这两种方法:

func showSpinner()
{
    let spinner = UIActivityIndicatorView(activityIndicatorStyle: .White)
    spinner.startAnimating()

    self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: spinner)
    self.navigationItem.hidesBackButton = true
}

func hideSpinner()
{
    self.navigationItem.leftBarButtonItem = nil
    self.navigationItem.hidesBackButton = false
}

viewDidLoad我致电showSpinner,然后在加载数据后,我致电hideSpinner。但backButton经常跳hideSpinner。如何解决?

enter image description here

1 个答案:

答案 0 :(得分:4)

删除微调器后,可以使用延迟显示后退按钮。像0.2秒或根据要求

func hideSpinner()
{
    self.navigationItem.leftBarButtonItem = nil
    dispatch_after(1, dispatch_get_main_queue()) { () -> Void in
        self.navigationItem.hidesBackButton = false
    };
}