【发布时间】:2015-07-01 04:43:10
【问题描述】:
我知道这里已经有一些这样的问题,但我无法让它们中的任何一个起作用。基本上,我有一个 ui 表视图,每个单元格中有一个标签和一个开关。每 14 个单元格,开关就会重复一次。 (开关1的状态会改变开关14、28等...)
这是我的代码:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Configure the cell:
let cell = tableView.dequeueReusableCellWithIdentifier("CompanyCell", forIndexPath: indexPath) as! CompanyCell
println(companies.count)
cell.companyName.text = companies[indexPath.row]
return cell
}
31 个公司名称的数组被加载到单元格中:
[Apple Inc, American Express Co, ... , Exxon Mobil Corp, Dow Jones]
标签(公司名称)位于单元格的左侧,开关位于单元格的右侧。
那么我怎样才能让细胞停止相互重复使用呢?
【问题讨论】:
-
你需要在你的
cellForRowAtIndexPath方法中设置开关的状态。 -
@rmaddy 我建议您添加一个答案,以便可以接受。我相信这是正确的解决方案。
标签: ios swift uitableview user-interface tableview