Finally, remove the remaining commented-out methods and replace them with these methods:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let deliverystatustype = self._entities[indexPath.row]
if deliverystatustype.selectable != 0 {
return self.getFUITimelineCell(deliverystatustype: deliverystatustype, indexPath: indexPath)
}
else {
return self.getFUITimelineMarkerCell(deliverystatustype: deliverystatustype, indexPath: indexPath)
}
}
private func getFUITimelineMarkerCell(deliverystatustype: DeliveryStatusType, indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "FUITimelineMarkerCell", for: indexPath)
guard let timelineCell = cell as? FUITimelineMarkerCell else {
return cell
}
timelineCell.nodeImage = self.getNodeImage(statusType: deliverystatustype.statusType!)
timelineCell.showLeadingTimeline = indexPath.row == 0 ? false : true
timelineCell.showTrailingTimeline = indexPath.row == self._entities.count - 1 ? false : true
timelineCell.eventText = self.getFormattedDateTime(timestamp: deliverystatustype.deliveryTimestamp!)
timelineCell.titleText = deliverystatustype.status
return timelineCell
}
private func getFUITimelineCell(deliverystatustype: DeliveryStatusType, indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "FUITimelineCell", for: indexPath)
guard let timelineCell = cell as? FUITimelineCell else {
return cell
}
timelineCell.nodeImage = self.getNodeImage(statusType: deliverystatustype.statusType!)
timelineCell.eventText = self.getFormattedDateTime(timestamp: deliverystatustype.deliveryTimestamp!)
timelineCell.headlineText = deliverystatustype.status
timelineCell.subheadlineText = deliverystatustype.location
return timelineCell
}
private func getFormattedDateTime(timestamp: LocalDateTime) -> String {
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd HH:mm"
return formatter.string(from: timestamp.utc())
}
private func getNodeImage(statusType: String) -> UIImage {
switch statusType {
case "start" : return FUITimelineNode.start
case "inactive" : return FUITimelineNode.inactive
case "complete" : return FUITimelineNode.complete
case "earlyEnd" : return FUITimelineNode.earlyEnd
case "end" : return FUITimelineNode.end
default : return FUITimelineNode.open
}
}
The first method tableView(_ tableView:, cellForRowAt indexPath:)
decides based on DeliveryStatus
property selectable
which specific timeline cell to render. This rendering is done via two private methods getFUITimelineMarkerCell(deliverystatustype:, indexPath:)
and getFUITimelineCell(deliverystatustype:, indexPath:)
.
These two private methods are implemented based on the code from the SAP Fiori for iOS Mentor app, but the code from the Mentor app has been split into two separate functions and control binding has already been implemented for easier implementation in this tutorial.
.
The final two private methods are helpers to format the timestamp into something more readable, and to get the correct FUITimelineNode
image indicator based on the DeliveryStatus
property StatusType
.