gpt4 book ai didi

ios - 如何在后端作业中实现纺车?

转载 作者:可可西里 更新时间:2023-11-01 00:49:03 26 4
gpt4 key购买 nike

我需要在后端作业中实现一个纺车。我的后端作业在一个单独的类中。

class ViewControllerA: UITableViewController {

// Code
var GetBackendRecordObj = GetBackendRecord(initparam:param);

// CODE TO START ANIMATION (SPINNING WHEEL)

self.view.addSubview(self.activityIndicator)
self.activityIndicator.bringSubview(toFront: self.view)
self.activityIndicator.startAnimating()

// CODE TO CALL THE BACKEND IS IN ANOTHER CLASS
GetBackendRecordObj.fetch_record()


}



class GetBackendRecord{

var transaction_id: String = ""
var current_email_id: String = ""

init(initparam: String) {
self.initparam = initparam

}

func fetch_record (){

do{
DispatchQueue.global(qos: .userInitiated).async {
//code
DispatchQueue.main.async { () -> Void in
//code to process response from backend
// NEED CODE TO STOP ANIMATION (SPINNING WHEEL)THAT WAS STARTED IN VIEWCONTROLLERA
})
}
}
}

如何在后端调用完成后访问 UITableViewcontroller,以便停止动画。或者如果在执行后端作业(在单独的类中)时有更好的启动/停止动画的方法,请告诉我。

最佳答案

将完成处理程序添加到 fetch_record:

func fetch_record(_ completionHandler: @escaping () -> Swift.Void) {
do{
DispatchQueue.global(qos: .userInitiated).async {
//code
DispatchQueue.main.async { () -> Void in
//code to process response from backend
completionHandler()
})
}
}
}

在您的 ViewController 中调用它时,您可以指定完成后要执行的操作:

GetBackendRecordObj.fetch_record() {
self.activityIndicator.stopAnimating()
}

关于ios - 如何在后端作业中实现纺车?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40914480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com