BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: problem with the NavigationController

Forums > Swift

Hey Guys.

I have a VC.

Inside that VC there is a custom UI View.

In that custom UI View there is a Collection View.

When I select a cell form that Collection View I want to present modally some other VC.

The problem is I don't have access to Navigation Controller that hold that first VC. When I do try to create a new Navigation Controller in didSelectItemAt, I get the error when I tap the cell that Navigation Controller is trying to present a VC that does not belong to its hierarchy.

How can I resolve that issue?

Many thanks.

1      

Hi,

so either you need to have hold on the container view controller, maybe setting it to your custom UI view,

or you can use the delegate pattern and the opening of the new view controller will be done in the class that implements delegate for this custom view,

or you can use the UIApplication.shared property and with some logic get the current top-most view controller and use it to present new one.

I think you can easily google examples about getting the top VC. The implementation might be a bit different if you are using something like TabBarController for you rootViewController or something that provides the sliding menu..

1      

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.