0

I would like to present a detail view (VC2) as a modal over the bottom half of a parent view (VC1). I need to use a segue to enable a callback. I can see that a modal sheet can be presented in this way but can only find examples using UINavigationController such as in this example this example or without a segue this one.

Is there any way to achieve this functionality when I call VC2 from VC1 using a segue?

My code is:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    //handles segues and updates on return
    if segue.identifier == "showAddChangeGas" {//settings segue
        if let vc2 = segue.destination as? AddChangeGasViewController {
            vc2.gasIndex = gasIndex
            vc2.callback = {//sets callback to update parameters and fields from new settings
                self.gasTableView.reloadData()
                self.gasIndex = nil
            }
        }
    }
}
Jim Burke
  • 251
  • 3
  • 14
  • I've not used segues in a long time (as a side note I would move away from them). But from what I remember when you create the connection in storyboard you get options in the activity inspector. Anything in there that can set the modalPresentationStyle? – OneCommentMan Jul 17 '23 at 13:03
  • @JimBurke the example I provided from your [previous question](https://stackoverflow.com/questions/76692874/) did not use a navigation controller. P.S. in the code you provided above, I don't see you changing any data from VC1 in the callback before reloading gasTableView. – P. Stern Jul 17 '23 at 18:13
  • Thanks for feedback - the only options on the segue are to present as modal, which I am using, no options to present a half screen - this involves detents which I can only see being used with non-segue modals. @P.Stern, I am using a global variable which is used throughout the app and I update this in VC2, however, your answer was spot on to allow me to use the callback() to trigger the table reload - which I couldn't achieve with a simple dismiss() of the modal. Once I added in your solution, I realised that my app would look much nicer with a half-modal, so now trying to get that to work. – Jim Burke Jul 17 '23 at 22:27

0 Answers0