gpt4 book ai didi

ios - cellForRowAtIndexPath 在源获取数据之前执行

转载 作者:搜寻专家 更新时间:2023-11-01 06:19:07 24 4
gpt4 key购买 nike

override func viewDidLoad() {
super.viewDidLoad()
print("loaded hie \(accountId)")
let request = SFRestAPI.sharedInstance().requestForQuery("SELECT Name,Id FROM Account where parentid='\(self.accountId)'");
//SFRestAPI.sharedInstance().send(request, delegate: self);
SFRestAPI.sharedInstance().sendRESTRequest(request, failBlock: {error in print(error)}, completeBlock: { responce in print(responce)
self.dataRows = responce["records"] as! [NSDictionary]
var counter = 0;
for i in self.dataRows
{
let requestForGrandChilds = SFRestAPI.sharedInstance().requestForQuery("select Name,Id from Account where parentid='\(i["Id"]!)'")
SFRestAPI.sharedInstance().sendRESTRequest(requestForGrandChilds,
failBlock:
{
error in print(error)
print("error block")
},
completeBlock:
{
responceChild in
self.grandChilds = responceChild["records"] as! [NSDictionary]
print(self.grandChilds)
self.dataOfGrandChilds["\(counter)"] = self.grandChilds
print(self.dataOfGrandChilds)
counter += 1

//Reloading My tableView
self.tableView.reloadData()
})
}
})
}

这是我的 viewDidLoad()。这里 dataOfGrandChilds 是一个字典,它是我的 TableView 单元格的来源。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("toViewChilds", forIndexPath: indexPath)
print("loading content\(self.dataOfGrandChilds)")
if let tempData = dataOfGrandChilds[indexPath.section]
{
cell.textLabel?.text = tempData[indexPath.row]["Name"] as? String
}
return cell
}

这是我的cellForRowAtIndexPath

问题是在 dataForGrandChilds 将内容保存在 viewDidLoad() 之前,cellForRowAtIndexPath() 正在执行。这就是为什么我不能填充 dataForGrandChilds 的值。请给我解决方案。

最佳答案

你只需要重新加载你的表格 View

yourTableView.reloadData()

在您的网络请求完成数据处理后放置此代码。

例如,您可以在 completeBlock:

的末尾添加它
override func viewDidLoad() {
super.viewDidLoad()
print("loaded hie \(accountId)")
let request = SFRestAPI.sharedInstance().requestForQuery("SELECT Name,Id FROM Account where parentid='\(self.accountId)'");
//SFRestAPI.sharedInstance().send(request, delegate: self);
SFRestAPI.sharedInstance().sendRESTRequest(request, failBlock: {error in print(error)}, completeBlock: { responce in print(responce)
self.dataRows = responce["records"] as! [NSDictionary]
var counter = 0;
for i in self.dataRows
{
let requestForGrandChilds = SFRestAPI.sharedInstance().requestForQuery("select Name,Id from Account where parentid='\(i["Id"]!)'")
SFRestAPI.sharedInstance().sendRESTRequest(requestForGrandChilds,
failBlock:
{
error in print(error)
print("error block")
},
completeBlock:
{
responceChild in
self.grandChilds = responceChild["records"] as! [NSDictionary]
print(self.grandChilds)
self.dataOfGrandChilds["\(counter)"] = self.grandChilds
print(self.dataOfGrandChilds)
counter += 1

//RELOAD TABLE VIEW HERE
yourTableView.reloadData()
})
}
})
}

关于ios - cellForRowAtIndexPath 在源获取数据之前执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37655709/

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