gpt4 book ai didi

swift - 将数组计数分配给 tableviewcell 标签

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

我有一个帖子数组,我从一个 PHP 文件返回所有帖子。我正在尝试将帖子数分配给 tableview 单元格中的标签。但是,当我将帖子数分配给标签时,我得到的是零值。有人能帮忙吗?

var posts = [AnyObject]()

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 1
} else {
return posts.count
}
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! InfoCell

print(posts.count)

cell.PostsLbl.text = String(posts.count)

return cell
}
}

最佳答案

看起来您正在从 PHP 文件异步获取 posts,在获取它们之后,您只重新加载第二部分。

关于swift - 将数组计数分配给 tableviewcell 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46039343/

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