Use the new Events system in DTTableViewManager 5.0
mainThe Events system has been rewritten to support 37 UITableViewDelegate and UITableViewDataSource methods. Events are categorized into two types based on whether the view is available at runtime:
- View-available events: These provide both the cell (view) and the model in the closure. Use these for interactions like selection or deselection.
- Data-only events: These occur when the view has not yet been created (e.g., calculating row height). These closures only provide the model and the
IndexPath.
Execution Logic:
DTTableViewManager uses responds(to:) to manage delegate methods. It follows this priority:
- Execute the registered event if types match.
- Call the delegate/datasource method on the
DTTableViewManageableinstance. - Fallback to default
UITableViewbehavior.
This allows you to use self-sizing cells safely; if you don't call heightForCell(withItem:_:), the manager won't intercept the height request, letting UITableView handle it.
// Example: Reacting to cell deselection (View-available event)
manager.didDeselect(FooCell.self) { cell, model, indexPath in
print("did deselect FooCell at \(indexPath), model: \(model)")
}
// Example: Height calculation (Data-only event)
manager.heightForCell(withItem: FooModel.self) { item, indexPath in
return 44.0
}