Introducing Controller - This is Neil in Transitional Delta

I'm currently trying to present a view controller using a UIPresentationController . My problem is when my user delegate transfers the call

 func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController? 

My nil view manager raises its exception. I present it from a view controller built into the navigation controller that is built into the tab bar controller. I tried to introduce it from these controllers on the same issue. It also works correctly when there is no special modal presentation, but my goal is to customize it. I call it when the button is selected and the code is presented below. mapTransitionDelegate is my custom delegate, which I save in the class property. In addition, EnlargedMapViewController() initialized to have a special modal presentation so that my transition delegate is called.

 var enlargedMapController = EnlargedMapViewController(); enlargedMapController.transitioningDelegate = mapTransitionDelegate; presentViewController(enlargedMapController, animated: true, completion: nil); 

I would like to know why this problem arises for future knowledge. At the moment, my subclass of UIPresentationController is not even initialized due to this exception.

+5
source share
1 answer

The designated initializer for the UIViewController (and, in turn, its subclasses) is equal to init(nibName:bundle:) . However, the documentation specifically states:

This is the designated initializer for this class. When using a storyboard to define your view controller and its associated views, you never initialize your view controller class directly. Instead, view controllers are created by the storyboard either automatically when segue is triggered or the application calls the instantiateViewControllerWithIdentifier method: the storyboard object method. When creating an instance of a view controller from a storyboard, iOS initializes a new view controller by calling it initWithCoder: instead of this method, and sets the nibName property to the nib file stored in the storyboard.

Calling EnlargedMapViewController() is the wrong way because it bypasses all the necessary mechanisms for Cocoa to find fragments. You must create an instance from nib using the initializer assigned to it, or at least by matching its nib file name with its class name (i.e. EnlargedMapViewController.xib ), so your call to EnlargedMapViewController(nibName: nil, bundle: nil) (passing nil) will cause Cocoa to search for a matching name.

But in fact, if you use storyboards everywhere, why not here? Just set the identifier for your scene and use instantiateViewControllerWithIdentifier: and enjoy the time and aggravation that you yourself saved.

0
source

All Articles