0
我想在完成塊之後刪除我的活動指示器。所以我做了這樣的事情。在swift中刪除完成處理程序中的UIActivityIndicator
func workflowSelected()
{
self.btnWorkflow.setTitle(dm.workflowName, for: .normal)
self.actIndApprover=UIActivityIndicatorView.init(frame: CGRect.init(x: self.btnFirstApprover.frame.size.width-40, y: 5, width: 30, height: 30))
self.actIndApprover.color=self.com.getfontColor()
self.actIndApprover.startAnimating()
self.btnFirstApprover.addSubview(self.actIndApprover)
self.callingFirstApprovers() { (staus) in
self.actIndApprover.stopAnimating()
self.actIndApprover.removeFromSuperview()
self.actIndApplyLeave.stopAnimating()
self.actIndApplyLeave.removeFromSuperview()
self.btnFirstApprover.addTarget(self, action: #selector(self.approverClicked), for: .touchUpInside)
if(staus)
{
print("Approvers loaded")
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "approverSelected"), object: nil)
}
else
{
self.btnFirstApprover.setTitle(self.lan.getConvertedLanguageString(word: "First Approver"), for: .normal)
}
}
}
但是這個activityindicator永遠不會刪除。我是否需要在主線程上刪除它?如果是這樣,我該怎麼做。請幫幫我。 感謝
UPDATE
func callingFirstApprovers(callback:@escaping(Bool)->Void)
{
let strBindedParam="workflowId=\(dm.workflowID!)&requesterCode=\(dm.strEmpCode!)&levelId=1"
let appendString=com.getServicePath(funcNAme: "workflow")
restAPI.prepareUrl(baseUrl:dm.tenantUrl,appendString: appendString, bindedParams: strBindedParam, isAuthorized: true, method: .get, jsonBody: [:]) { (status) in
if(status=="success")
{
self.com.removeProgress()
print(self.dm.responseArray)
self.arrayApproversFullArray=self.dm.responseArray
if(self.dm.responseArray.count>0 && self.dm.responseArray != nil)
{
let obj=self.dm.responseArray[0] as! [String:Any]
print("object approver------\(obj)")
if let objApprover:Array<Any> = obj["Approvers"] as? Array<Any>
{
if(objApprover.count>0)
{
self.dm.arrayFirstApprovers=objApprover
let approverInnerObj=objApprover[0] as! [String:Any]
print(objApprover)
if let strApproverCode=approverInnerObj["EmployeeCode"] as? Int
{
self.dm.strApproverCode=String(strApproverCode)
}
if let strApproverNAme=approverInnerObj["Name"] as? String
{
self.btnFirstApprover.setTitle(strApproverNAme, for: .normal)
self.dm.strApproverNAme=strApproverNAme
}
print("Approvers are more than 1")
callback(true)
}
else
{
callback(false)
}
}
callback(false)
}
else{
callback(false)
}
}
else
{
print(self.dm.errorMessage)
self.com.showAlertMessage()
callback(false)
}
}
}
我這樣做,似乎它的呼叫多次。有什麼理由呢? – user1960169
此調度塊正在運行多次 – user1960169
我不知道您的代碼或調用。這不是調度本身,這是你的實施多次調用 – Matz