UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

3      

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..

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.