I want to present a custom view controller within a navigation controller within modal view. To do this I made a view in interface builder, added a container view, and embedded the contained view in a navigation controller. The contained view is my custom view controller, DetailViewController.
I have to add dependencies to the DetailViewController object to at runtime. Here’s the method where I’ll be presenting the DetailViewController:
override func tableView(_: UITableView, didSelectRowAt: IndexPath) {
guard let record = records[didSelectRowAt.row] else { return }
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let containerView = storyBoard.instantiateViewController(withIdentifier: "DetailContainer")
containerView.modalPresentationStyle = .overFullScreen
self.present(detailContainer, animated: true, completion: nil)
}
How can I add the record to DetailViewController? I tried to access children of the container view, but the array is empty. This Apple document says
The children must be instantiated at the same time as the parent so that the appropriate parent-child relationships can be created.
I'm not sure how to achieve that.