Slide 17
Slide 17 text
MATT GALLAGHER, TRY! SWIFT NYC 2017: VIEW-STATE DRIVEN APPLICATIONS
VIEW-STATE DRIVEN (DATA-DRIVEN)
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
ViewState.shared.setDetailSelection(uuid: sortedTimezones[indexPath.row].uuid)
}
@objc func handleViewStateNotification(_ notification: Notification) {
let detailView = ViewState.shared.topLevel.detailView
if let uuid = detailView?.uuid, Document.shared.timezones[uuid] != nil, lastPresentedUuid != uuid {
lastPresentedUuid = uuid
performSegue(withIdentifier:
notification.userActionData != nil ? "detail" : "detailWithoutAnimation", sender: self)
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetail", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
let timezone = sortedTimezones[indexPath.row]
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.timezone = timezone
}
}
}
CHANGING DETAIL VIEW (PRESENTATION-DRIVEN)