【发布时间】:2018-03-22 17:29:25
【问题描述】:
我有一个包含 4 个部分的表格视图。在第 2、3 和 4 节中,我想要一个 + 按钮来将信息添加到“已保存”数组。我有添加信息的逻辑设置,但我遇到了表格视图单元格的问题。
我不希望 + 按钮出现在第 0 部分,因为这是我们添加数据的地方。这是我的 cellForRowAt 方法...
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) as! SchoolTableViewCell
// Configure the cell...
if indexPath.section == 0 {
cell.textLabel?.text = "Test"
cell.addFavoritesButton.removeFromSuperview()
} else if indexPath.section == 1 {
cell.textLabel?.text = Items.sharedInstance.elementaryList[indexPath.row]
} else if indexPath.section == 2 {
cell.textLabel?.text = Items.sharedInstance.intermediateList[indexPath.row]
} else if indexPath.section == 3 {
cell.textLabel?.text = Items.sharedInstance.highschoolList[indexPath.row]
}
return cell
一开始效果很好!但是如果我向下滚动,越来越多的单元格将删除该按钮。由于可重复使用的单元格,它不限于第 0 节。
谁能想到一个更好的方法来删除第一部分的这个按钮?
【问题讨论】:
-
因为您正在重用已完成
cell.addFavoritesButton.removeFromSuperview()的单元格。所以当它被重复使用时...... * 噗 * 再见,永远甜蜜甜蜜addFavoritesButton,不管你在哪个部分
标签: ios swift xcode uitableview