我想把数据从TableView转到细胞。所以我用dataSource编写了cell.count = groups[indexPath.row].count。在TableViewCell中声明了var count: Int!。当我在layoutSubviews()中打印计数时,它会调用相同的数据两次,所以我不能做我想做的事情。当我在dataSource方法中打印groupsindexPath.row.count时,它正常打印一次。我该如何解决这个问题?
示例)如果计数序列为1 2 1,则在单元计数变量中打印1 1 2 2 1 1
发布于 2021-08-29 21:30:54
我猜我写代码是因为你写的东西里没有代码。
let groups : [Int] = [1,2,3,4,5]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return self.groups.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let rowData = self.groups[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "GROUP_CELL")
cell?.textLabel?.text = rowData
return cell!
}这将不会两次输出“group”的内容。这是你想要的吗?
https://stackoverflow.com/questions/68976179
复制相似问题