Phil
Phil

Reputation: 71

Present view controller modally from two source controllers, with navigation bar

I'm searching for what I believe must be the simple solution to showing (modal) the same destination view controller (an edit screen - with navigation controller and nav bar) from two source view controllers: 1) the root list, and 2) the view item screen.

Here's the sort of thing I mean:

Storyboard

My understanding is that the relationship segue between nav controller and destination VC can only be connected to one source VC? Every time I fixed one, the other broke.

All my attempt to implement prepare for segue generated fatal init coder errors.

Removing the navigation controller and implementing two @IBSegueAction func's got the segues working but removed the required navigation bar (and its save, cancel buttons).

I'm sure I'm missing something simple to elegantly create this workflow. But I can't find it.

I'm using Xcode 14.3 and building in UIKit.

Upvotes: 0

Views: 270

Answers (1)

DonMag
DonMag

Reputation: 77672

Many different ways to handle this type of navigation / flow.

One approach...

Instead of embedding your "Edit" table view controller in (another) navigation controller, add a UINavigationBar to the table view controller.

Now you can present it from

  • either the "+ add new" button on your "List" table view, or
  • from the "Edit" button when viewing the item

This is basically how it would look:

enter image description here

Really, really quick example project: https://github.com/DonMag/NavApproach

Upvotes: 0

Related Questions