I'm developing app with a structure like this:
Edit: There's a common tab bar controller on main.storyboard
main.Storyboard -> NavController -> (relationship) ViewControllerA -> (show/push segue) ViewControllerB
secondary.Storyboard -> NavController -> (relationship) ViewControllerC
From ViewControllerC, I need to segue to ViewControllerB. I'm doing this using a Storyboard reference. The segue works, dependencies are passed in the segue, but I have one programmatic view that I load which isn't loading when the VC is presented from ViewControllerC on secondary.Storyboard and loads normally when presented with a storyboard segue
Here's how I'm triggering the segue to ViewControllerB:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let someObject = fetchedResultsController.object(at: indexPath).someRepresentation
performSegue(withIdentifier: "theIdentifier", sender: someObject)
}
Here's how I'm handling the segue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "theIdentifier" {
guard let destination = segue.destination as? ViewControllerB,
let sender = sender as? SomeCustomClass else { return }
destination.receivedObject = sender
}
}
I'm creating the views and adding to the view's subView in ViewWillAppear. I've also tried this in ViewDidAppear with no changed effect. Again, the views are created when the ViewController is presented from the same storyboard
Here's how I'm eventually creating the views
let webNavView = WebNavToolbarView(viewLayoutMarginsGuide: view.layoutMarginsGuide)
let yPosition: CGFloat = webNavView.frame.height / 4
let xOffset: CGFloat = 8
let backButton = createButton(
image: .back,
xPosition: xOffset,
yPosition: yPosition,
selector: #selector(goBackPressed)
)
let forwardButton = createButton(
image: .forward,
xPosition: backButton.frame.maxX + xOffset,
yPosition: yPosition,
selector: #selector(goForwardPressed)
)
// FIXME: Doing this just to get the width for the createButtonMethod's xPosition parameter
let homeButton = createButton(
image: .home,
xPosition: webNavView.frame.maxX - forwardButton.frame.width - xOffset,
yPosition: yPosition,
selector: #selector(goHomeButtonPressed)
)
webNavView.translatesAutoresizingMaskIntoConstraints = false
webNavView.addSubview(backButton)
webNavView.addSubview(forwardButton)
webNavView.addSubview(homeButton)
self.view.addSubview(webNavView)
The webNavView is using the layoutGuide that's passed in to get its width. X and Y are 0,0
All views are being created without constraints (using frames). The createButton method is just positioning the buttons after calling an initializer that styles them.
If I print view.subViews, webNavView is in there, but it doesn't appear on screen or in the Views Debugger. It's height and width are both 0, though it's height is hard-coded to 60
Also, if I add the toolbar to parent.view, it gets added but doesn't respect any of the safe area (it gets placed over the status bar)
Subviews also print out with the right position. But again, nothing even shows in Views Debugger
Main.storyboard:
secondary.storyboard:
storyboard reference: