我有一个帖子数组,我从一个 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/