ios - 从 TableView 中调用了两次 TableViewCell 数据
问题描述
我想从 TableView 获取数据到 Cell。所以我cell.count = groups[indexPath.row].count
在dataSource中写了。在 TableViewCellvar count: Int!
中声明。当我在 layoutSubviews() 中打印计数时,它会两次调用相同的数据,所以我不能做我想做的事。当我在 dataSource 方法中打印 groups[indexPath.row].count 时,它会正常打印一次。我怎么解决这个问题?
示例)如果计数序列为 1 2 1,则在单元格计数变量中打印 1 1 2 2 1 1
解决方案
我想我写了代码,因为你的写作中没有代码。
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!
}
这不会两次输出“组”的内容。这是你想要的吗?
推荐阅读
- php - 将 php 部署到 aws lambda
- android - 在改造的RequestBody中转换日期的时区
- email - 如何构建 DKIM 标头
- elasticsearch - Elasticsearch on cloudfoundary
- node.js - 如何更改 NodeJS 中响应的状态码?
- apache-spark - how to measure the lag of a kafka topic with consumer being a spark?
- linux - Visual Studio 代码调试器错误:“找不到任务‘gcc build active file’
- node.js - SyntaxError: Unexpected Indentifier while compiling ejs problem
- python - Substracting inner rings from a list of polygons
- reactjs - TypeScript error: Property 'children' does not exist on type 'ReactNode'