gpt4 book ai didi

ios - Swift - 填充表行

转载 作者:行者123 更新时间:2023-11-29 01:19:40 25 4
gpt4 key购买 nike

我正在用从后端获取的名称列表填充一个表(作为用户名,然后作为 friend 的名字)。

数组显示所有内容都在那里(它应该包含 2 条记录),但由于某种原因,我做了一些愚蠢的事情,导致 TableView 中只显示一条记录(单行)。

我个人认为这是由于实现 cellForRowAtIndexPath 方法而导致的错误。这是代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {

let cellIdentifier = "cell"

var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? FriendsCell
if cell == nil {
cell = FriendsCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
}

// Configure the cell to show name of friend
print("Index Row: \(indexPath.row)")
cell!.name.text = self.friendsInfoListArray[indexPath.row]["name"] as? String


return cell
}

有人能找出哪里出了问题吗?如前所述,数组中有两条记录,但只显示一条记录。

谢谢

更新:

reloadTable 代码:

override func queryForTable() -> PFQuery {

self.loadFriendsUsernames({ (result)->Void in
if(result.count > 0)
{
self.loadFriendsInfo({ (result)->Void in
if(result.count > 0)
{
print(self.friendsInfoListArray)
self.tableView.reloadData()

print("Success Loading Friends Info Array")
}else{
print("Error Loading Friends Info Array")
}
})
}else{
print("Error Loading Friends Usernames Array")
}

})


let query = PFQuery(className: self.parseClassName!)
let currentUser = PFUser.currentUser()
query.whereKey("appUsername", equalTo: currentUser!["appUsername"])
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if self.objects!.count == 0 {
query.cachePolicy = .CacheThenNetwork
}

return query
}

最佳答案

假设您要在 viewDiDLoad: 方法中获取好友列表。

override func queryForTable() -> PFQuery {

self.loadFriendsUsernames({ (result)->Void in
if(result.count > 0)
{
self.loadFriendsInfo({ (result)->Void in
if(result.count > 0)
{
print(self.friendsInfoListArray)
self.friendsInfoListArray = result
self.tableView.reloadData()

print("Success Loading Friends Info Array")
}else{
print("Error Loading Friends Info Array")
}
})
}else{
print("Error Loading Friends Usernames Array")
}

})


let query = PFQuery(className: self.parseClassName!)
let currentUser = PFUser.currentUser()
query.whereKey("appUsername", equalTo: currentUser!["appUsername"])
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if self.objects!.count == 0 {
query.cachePolicy = .CacheThenNetwork
}

return query
}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return self.friendsInfoListArray.count;

}

关于ios - Swift - 填充表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34764317/

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