0
votes

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)

Checking webNavView's frame: webNavView's frame

Subviews also print out with the right position. But again, nothing even shows in Views Debugger

Main.storyboard:

Main.storyboard

secondary.storyboard:

secondary.storyboard

storyboard reference:

storyboard reference

2
@matt I don't believe that's true. He can modally present ViewControllerB from ViewControllerC or he can push it and in this case ViewControllerB will just be another viewController in second storyboard's nav controller's stack.rs7
Can you share the code that creates the views when loading ViewControllerB? Also, can you specify what kind of segue you are using from VCC to VCB?rs7
@matt the ViewController gets pushed onto the stack just fine. It's a different storyboard, so it's not going "backward"froggomad
@rs7 I'm using a storyboard reference and show/push seguefroggomad
It's unclear to me how you are able to access VCB using a segue from a different storyboard while VCB is not the entry point of its own storyboard.rs7

2 Answers

1
votes

I think I may have found your problem. You said you were laying out your views using frames, yet you are setting: webNavView.translatesAutoresizingMaskIntoConstraints = false. You need to get rid of this line of code because this tells the compiler that you are laying out your view using autolayout, and so it will ignore the frame. And since don't have any auto layout constraints defined, your webview is not showing on the screen.

I would also double check to make sure that you are not setting translatesAutoresizingMaskIntoConstraints to false for the webNavView's subviews.

0
votes

Setting the webNavView.frame.origin.y = view.safeAreaInsets.top resolved the issue