AliSoftware / AliSoftware/Reusable

getting error on using cellType(for indexPath:)

未關閉
#101 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Swift
星號
3k
分支
231
PR 合併指標
30 天內沒有已合併 PR

描述

on trying below getting erros

`class ParentCell: UITableViewCell, Reusable {}
class Child1Cell: ParentCell {}
class Child2Cell: ParentCell {}

func cellType(for indexPath: NSIndexPath) -> ParentCell.Type {
return indexPath.row.isMultiple(of: 2) ? Child1Cell.self : Child2Cell.self
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellClass = self.cellType(for: indexPath)
// As `self.cellType(for:)` always returns a `ParentCell` (sub-)class, the type
// of the variable `cell` below is infered to be `ParentCell` too. So only methods
// declared in the parent `ParentCell` class will be accessible on the `cell` variable.
// But this code will still dequeue the proper type of cell (Child1Cell or Child2Cell).
let cell = tableView.dequeueReusableCell(for: indexPath, cellType: cellClass)
// Then fill the content of your cell (using methods/properties from `ParentCell` type)
return cell
}`

<2020-03-08 20:37:13.830457+0500 ReusableDemo iOS[18026:477363] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '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). Cell identifier: MyXIBTextCell, index path: {length = 2, path = 1 - 0}>

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。