0
votes

I have an iOS application that uses a UITabBarController. It has 3 tabs, where each tab contains a UINavigationController as the root. In one of my tabs I'm presenting a ViewController modally and full screen. From that view controller I present a custom modal ViewController using my own implementation of UIViewControllerContextTransitioning. All works fine. But I wanted instead to make the parent view not be a modal full screen but instead be pushed on the nav stack. The push works fine but when I go to present the custom modal in this case it doesn't work. What I can see in the debugger is that the transitionContext's from VC is my UITabBarController. I confirmed that the call to present was made on the ViewController I intended (i.e. the one that was pushed). I'm not able to figure out why this is failing. Has anyone experienced issues like this. I can try to post some example code here to illustrate if that's helpful or my description isn't clear.

Here's some code snippets: Note the Router object manages presentation. For the most part it just forwards on the pushViewController or present call to the proper view controller. The VCFactory returns the desired ViewController.

Here is the first push of a view controller. If instead of pushViewController I use "present" (to present the vc as a full screen modal) all works fine.

Router.pushViewController(VCFactory.ScorecardTab.scorecard(scorecard: selectedScorecard), animated: true)

Here is the presentation of the modal that I'm trying to do. I pass in a presentation style of .custom and I pass in the transition delegate. In this case the transition delegate is the view controller that was displayed by the previous push (or present) as seen in the code above.

Router.present(ViewControllerFactory.ScorecardTab.scoreEntry(selectedCourse: course, selectedPlayer: tappedPlayer, selectedHoleNumber: tappedHoleNumber, scoreEntryDelegate: self, scoreEntryDataSource: AnyEquatableScoreCardViewDataSource(self)), presentationStyle: .custom, transitioningDelegate: transitionDelegate)

Finally here is my transition delegate implementation:

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    let fromView = transitionContext.viewController(forKey: .from)!.view!
    let toView = transitionContext.viewController(forKey: .to)!.view!

The from view controller in this case is showing up as my UITabBarController instead of the expected view controller that was pushed in the first code snippet above.

In the presenting view controllers viewDidLoad I tried adding setting definesPresentationContext using:

    override func viewDidLoad() {
        super.viewDidLoad()
        
        definesPresentationContext = true

In the debugger i confirmed that it was set to true, but I'm still seeing the UITabBarController as the "from" VC.

1

1 Answers

1
votes

I guess you are talking about UIViewController.definesPresentationContext. See https://developer.apple.com/documentation/uikit/uiviewcontroller/1621456-definespresentationcontext?language=objc

Set definesPresentationContext = YES to the VC you want to be from VC.

I could help more if you provided your VC hierarchy with a very short example of your code. It is a bit difficult to figure out your setup and the behavior that you expect.