Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting error on using cellType(for indexPath:) #101

Open
Mangoman3 opened this issue Mar 8, 2020 · 0 comments
Open

getting error on using cellType(for indexPath:) #101

Mangoman3 opened this issue Mar 8, 2020 · 0 comments

Comments

@Mangoman3
Copy link

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: <NSIndexPath: 0x8edbb09a3c0860b8> {length = 2, path = 1 - 0}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant