The following document describe the events available for FlowKit when you are using it to manage UITableView
.
Events are available at 3 different levels:
- Director Events: all general purpose events which are not strictly related to the single model's management. It includes general header/footer and scrollview delegate events.
- Adapter Events: each adapter manage a single pair of Model (
M: ModelProtocol
) and View (C: CellProtocol
). It will receive all events related to single model instance configuration (dequeue, item size etc.). - Section Events:
TableSectionView
instances manage custom view header/footer of a specificTableSection
. It will receive events about dequeue, view's visibility.
-
TableDirector
- Events
- Received Context
- Example
-
TableAdapter
- Events
- Received Context
- Example
-
TableSectionView
- Events
- Received Context
- Example
--
The following events are available from TableDirector
's .on
property.
sectionForSectionIndex: ((_ title: String, _ index: Int) -> Int)
(name of the section is read automatically fromindexTitle
property of the section)willDisplayHeader: ((HeaderFooterEvent) -> Void)
willDisplayFooter: ((HeaderFooterEvent) -> Void)
endDisplayHeader: ((HeaderFooterEvent) -> Void)
endDisplayFooter: ((HeaderFooterEvent) -> Void)
where HeaderFooterEvent
is just a typealias which contains the relevant information of the header/footer.
HeaderFooterEvent = (view: UIView, section: Int, table: UITableView)
tableView.director.on.willDisplayHeader = { ctx in
print("Will display header for section \(ctx.section)")
}
The following properties are used to manage the appearance and the behaviour for a pair of <model,cell> registered into the table.
Each event will receive a Context<M,C>
which contains a type safe instance of the involved model and (if available) cell.
The following events are reachable from TableAdapter
's .on
property.
dequeue : ((EventContext) -> (Void))
canEdit: ((EventContext) -> Bool)
commitEdit: ((_ ctx: EventContext, _ commit: UITableViewCellEditingStyle) -> Void)
canMoveRow: ((EventContext) -> Bool)
moveRow: ((_ ctx: EventContext, _ dest: IndexPath) -> Void)
prefetch: ((_ models: [M], _ paths: [IndexPath]) -> Void)
cancelPrefetch: ((_ models: [M], _ paths: [IndexPath]) -> Void)
rowHeight: ((EventContext) -> CGFloat)
rowHeightEstimated: ((EventContext) -> CGFloat)
indentLevel: ((EventContext) -> Int)
willDisplay: ((EventContext) -> Void)
shouldSpringLoad: ((EventContext) -> Bool)
editActions: ((EventContext) -> [UITableViewRowAction]?)
tapOnAccessory: ((EventContext) -> Void)
willSelect: ((EventContext) -> IndexPath?)
tap: ((EventContext) -> TableSelectionState)
willDeselect: ((EventContext) -> IndexPath?)
didDeselect: ((EventContext) -> IndexPath?)
willBeginEdit: ((EventContext) -> Void)
didEndEdit: ((EventContext) -> Void)
editStyle: ((EventContext) -> UITableViewCellEditingStyle)
deleteConfirmTitle: ((EventContext) -> String?)
editShouldIndent: ((EventContext) -> Bool)
moveAdjustDestination: ((_ ctx: EventContext, _ proposed: IndexPath) -> IndexPath?)
endDisplay: ((_ cell: C, _ path: IndexPath) -> Void)
shouldShowMenu: ((EventContext) -> Bool)
canPerformMenuAction: ((_ ctx: EventContext, _ sel: Selector, _ sender: Any?) -> Bool)
performMenuAction: ((_ ctx: EventContext, _ sel: Selector, _ sender: Any?) -> Void)
shouldHighlight: ((EventContext) -> Bool)
didHighlight: ((EventContext) -> Void)
didUnhighlight: ((EventContext) -> Void)
canFocus: ((EventContext) -> Bool)
EventContext
is a typealias for Adapter's Context<M,C>
with M
is the ModelProtocol
instance managed by the table and C
is CellProtocol
instance used to represent data.
The following properties are available:
table: UITableView
: target table instanceindexPath: IndexPath
: target model index pathmodel: M
: target model instance (type-safe)cell: C?
: target cell instance (type-safe) / if available
let contactAdapter = TableAdapter<Contact,CellContact>()
// intercept tap
contactAdapter.on.tap = { ctx in
print("User tapped on \(ctx.model.fullName)")
return .deselectAnimated
}
// dequeue event, used to configure the UI of the cell
contactAdapter.on.dequeue = { ctx in
ctx.cell?.labelName?.text = ctx.model.firstName
ctx.cell?.labelLastName?.text = ctx.model.lastName
}
The following events are received from single instances of headerView
/footerView
of a TableSection
instance and are related to header/footer events.
The following events are available from TableSectionView
's .on
property.
height
event is required.
dequeue: ((Context<T>) -> Void)
height: ((Context<T>) -> CGFloat)
estimatedHeight: ((Context<T>) -> CGFloat)
willDisplay: ((Context<T>) -> Void)
endDisplay: ((Context<T>) -> Void)
didDisplay: ((Context<T>) -> Void)
let header = TableSectionView<TableExampleHeaderView>()
header.on.height = { _ in
return 150
}
header.on.dequeue = { ctx in
ctx.view?.titleLabel?.text = "\(articles.count) Articles"
}
let section = TableSection(headerView: header, models: articles)
Where Context<T>
is a structure which contains the following properties of the section view instance:
type: SectionType
:header
if target view is header,footer
for footer viewtable: UITableView
: target table instanceview: T
: type-safe target instance of the header/footer view setsection: Int
: target sectiontableSize: CGSize
: size of the target table