Open rbsgn opened 8 years ago
What's interesting is that Show Detail segue gets called before tableView:didSelectRowAtIndexPath:
and detail view controller ends up with no data from context supplied by master view controller.
I published my playground project at https://github.com/rbuussyghin/VisitedStoryboards for your convenience.
Thanks I'll take a look at the work you've done, interested to find the limitations which may well exist. In my example it was necessary for me to subclass and create Visitable versions of the standard UIKit ViewControllers and then change the Controller classes used in my storyboard. These are in the file "StoryboardViewController.swift" and I think it might only require that you take this and add one for UISplitViewController.
What's interesting is that Show Detail segue gets called before tableView:didSelectRowAtIndexPath: and detail view controller ends up with no data from context supplied by master view controller.
It's the case that when you have storyboard triggered segues from table view cells prepare(for ..) happens first and so typically you move the work from didSelect: to prepare(for ...) - in our case that means to the "StoryboardController" extension. DidSelect is almost redundant in this approach.
The trick is to get the data you want from the source during this processing. In my examples I've achieved this via a 'context' object which is the receiver of data from the different view controllers. So for instance you might in the TableViewController class override prepare(for ..) set the selected data for the next screen to the context based on tableView.indexPathOfSelectedCell and then call super prepare(for ...) where the destination can be configured using data captured to the context.
Hi,
Thank you for sharing the idea of using visitors with storyboard segues! I've tried to incorporate your technique into Master-Detail Application template and found an issue which I don't know how to resolve elegantly with your technique.
Master-Detail Application template uses
UISplitViewController
where master view controller (basically aUITableViewController
subclass) presents detail view controller which is wrapped intoUINavigationController
. This means thatUINavigationController
or (StoryboardNavigationController
?) must conform toStoryboardVisitableScene
and it must implementfunc accept(visitor: StoryboardController)
. How doesaccept
should be implemented? Should I try to cast every possible root view controller of a navigation controller and callvisit
like that?Ping me if you need a sample project.