我正在使用来自" https://github.com/erangaeb/dev-notes/blob/master/swift/ViewControllerUtils.swift"的活动指示器。我尝试在我的视图中使用它,但指标似乎没有停止。我已将其包含在我的视图中,如下所示:
ActivityIndicatorView().showActivityIndicator(uiView: self.view)
我使用以下代码停止:
ActivityIndicatorView().hideActivityIndicator(uiView: self.view)
但我不知道为什么指标正在停止。 我的更多代码如下:
Alamofire.request(diaryViewUrl, method: .get, parameters: [:]).responseJSON {
response in
if response.result.isSuccess{
ActivityIndicatorView().showActivityIndicator(uiView: self.view)
let dataFetched : JSON = JSON(response.result.value!)
self.diaryDateTimeText = dataFetched["diary_datetime"].string
self.diaryLocText = dataFetched["diary_loc"].string
self.diaryText = dataFetched["diary_text"].string
self.diaryTags = dataFetched["tags"].arrayObject as? [String]
ActivityIndicatorView().hideActivityIndicator(uiView: self.view)
self.topBar()
self.showViews()
self.scrollView.addSubview(self.containerView)
self.view.addSubview(self.scrollView)
}else{
print("Error \(String(describing: response.result.error))")
}
}
答案 0 :(得分:0)
您必须在发出Alamofire请求之前显示活动指示符,当您获得成功或错误状态的响应时,您可以隐藏它,现在同时调用show和hide。
答案 1 :(得分:0)
对我来说很好。请试一试
ActivityIndicatorView().showActivityIndicator(uiView: self.view)
Alamofire.request(diaryViewUrl, method: .get, parameters: [:]).responseJSON {
response in
ActivityIndicatorView().hideActivityIndicator(uiView: self.view)
if response.result.isSuccess{
let dataFetched : JSON = JSON(response.result.value!)
self.diaryDateTimeText = dataFetched["diary_datetime"].string
self.diaryLocText = dataFetched["diary_loc"].string
self.diaryText = dataFetched["diary_text"].string
self.diaryTags = dataFetched["tags"].arrayObject as? [String]
self.topBar()
self.showViews()
self.scrollView.addSubview(self.containerView)
self.view.addSubview(self.scrollView)
}else{
print("Error \(String(describing: response.result.error))")
}
}