导航栏上有一个Save
(系统项)BarButtonItem
当用户点击此UIActivityIndicatorView
按钮时,我在导航栏上显示Save
我想要在某些条件下再次出现这个Barbutton(保存)。首先我认为问题是我在customView上添加了一个指示器,所以我不需要隐藏barbutton.It在启动指示器后会自动隐藏。但现在不知道如何再次显示保存按钮。或如何从customView
这就是我正在做的事情
@IBOutlet weak var saveButtonOutlet: UIBarButtonItem!
var activityIndicatorView:UIActivityIndicatorView!
func showActivityIndicator() {
activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White)
activityIndicatorView.frame = CGRectMake(0, 0, 14, 14)
activityIndicatorView.color = UIColor().blueColorIOS()
activityIndicatorView.startAnimating()
let barButtonItem = UIBarButtonItem(customView: activityIndicatorView)
self.navigationItem.rightBarButtonItem = barButtonItem
}
@IBAction func saveButtonClicked(sender: UIBarButtonItem) {
showActivityIndicator()
ServerRequest.postToServer(url, params: params){
result, error in
if let result = result {
let code = result["code"] as? Int
print(result)
if (code==200){
dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), { ()->() in
self.activityIndicatorView.hidden = true
self.activityIndicatorView.hidesWhenStopped = true
//here want to show again "saveButtonOutlet"
})
}
}
}
}
}
答案 0 :(得分:0)
我认为您需要做的就是将self.navigationItem.rightBarButtonItem
重置为saveButtonOutlet。
现在为我工作。
答案 1 :(得分:0)
所以一种方法是再次创建“保存”按钮,然后再次设置rightBarButtonItem
:
...
self.activityIndicatorView.hidden = true
self.activityIndicatorView.hidesWhenStopped = true
let barButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Save, target: self, action: "saveButtonClicked:")
self.navigationItem.rightBarButtonItem = barButtonItem
我还会将self.activityIndicatorView.hidden = true
替换为self.activityIndicatorView.stopAnimating()
以正确使用hidesWhenStopped
属性。