崩溃:试图使同一索引路径的多个单元格出列,这是不允许的



我有一个表视图数据源函数来从工厂方法函数构建一个单元格。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return OWTableViewOrganizer.instance.configureCell(at: indexPath)!
}

工厂方法如下:

func configureCell(at indexPath: IndexPath) -> UITableViewCell? {

var cell = UITableViewCell()

switch indexPath.section {
case thisWorkoutSections.barbel.sectionNumber():
cell = barebellCell(indexPath: indexPath)
break
case thisWorkoutSections.lastWorkout.sectionNumber():           
cell = lastWorkoutCell(indexPath: indexPath)
break
case thisWorkoutSections.personalRecord.sectionNumber():
cell = personalRecordCell(indexPath: indexPath)
break
case thisWorkoutSections.notes.sectionNumber():

break
default:
break
}

return cell
}

我有这个代码来构建细胞:

func lastWorkoutCell(indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: WorkoutSetTableViewCell.cellIdentifier(), for: indexPath) as! WorkoutSetTableViewCell

if OWTableViewOrganizer.instance.lastWorkoutExerciseSets.count > 0 {
if indexPath.row < OWTableViewOrganizer.instance.lastWorkoutExerciseSets.count {
let logExerciseSet = OWTableViewOrganizer.instance.lastWorkoutExerciseSets[indexPath.row]
let setNumber = indexPath.row + 1
if let weight = logExerciseSet.weight?.doubleValue, let reps = logExerciseSet.reps?.intValue {
cell.setupCellWithData(setNumber: setNumber, weight: weight, reps: reps)
}
} else {
cell.setupCellWithData(setNumber: -1, weight: 0, reps: 0)
}
} else {
cell.setupCellWithData(setNumber: -1, weight: 0, reps: 0)
}

return cell
}

但对我来说,这条线路有时会崩溃:

let cell = tableView.dequeueReusableCell(withIdentifier: WorkoutSetTableViewCell.cellIdentifier(), for: indexPath) as! WorkoutSetTableViewCell

有错误:

Attempted to dequeue multiple cells for the same index path, which is not allowed. If you really need to dequeue more cells than the table view is requesting, use the -dequeueReusableCellWithIdentifier: method (without an index path)

我知道这里的代码风格和设计并不理想,如果你有意见,请跳过这个。

我不知道在哪里找,我试着简单地删除indexPath,但它看起来没有帮助,或者带来更多的问题:

let cell = tableView.dequeueReusableCell(withIdentifier: WorkoutSetTableViewCell.cellIdentifier()) as! WorkoutSetTableViewCell

我有一个控制器,它在顶部显示另一个(就像在苹果音乐中一样(,我可以向下滑动显示底部控制器,向上滑动返回顶部控制器。我在日志中注意到我有一些演示警报,不确定这是否是我需要处理的问题来解决上述问题,但JFY信息。

似乎有两个表视图触发

tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)

在中,您只能从1个表视图中退出单元格

let cell = tableView.dequeueReusableCell(withIdentifier: WorkoutSetTableViewCell.cellIdentifier(), for: indexPath) as! WorkoutSetTableViewCell

您应该尝试从传递tableView

tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)

lastWorkoutCell(indexPath: IndexPath)

(将变为lastWorkoutCell(indexPath: IndexPath, tableView: UITableView)(,并从tableView中出列信元

最新更新