Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysterious crash when presenting a view controller using a custom UIPresentationController subclass

I'm experiencing a crash on iOS 8.1 (device and simulator) when attempting to do a custom presention a UIViewController with a custom UIPresentationController subclass.

The exception raised prints the following to the console:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSSetM addObject:]: object cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x03bc9946 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x03479a97 objc_exception_throw + 44
    2   CoreFoundation                      0x03ae018b -[__NSSetM addObject:] + 699
    3   UIKit                               0x023bf389 -[UIPeripheralHost(UIKitInternal) _beginPinningInputViewsOnBehalfOfResponder:] + 50
    4   UIKit                               0x01f81188 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 2306
    5   UIKit                               0x01fb47ab __40+[UIViewController _scheduleTransition:]_block_invoke + 18
    6   UIKit                               0x01e7a0ce ___afterCACommitHandler_block_invoke + 15
    7   UIKit                               0x01e7a079 _applyBlockToCFArrayCopiedToStack + 415
    8   UIKit                               0x01e79e8e _afterCACommitHandler + 545
    9   CoreFoundation                      0x03aec9de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    10  CoreFoundation                      0x03aec920 __CFRunLoopDoObservers + 400
    11  CoreFoundation                      0x03ae235a __CFRunLoopRun + 1226
    12  CoreFoundation                      0x03ae1bcb CFRunLoopRunSpecific + 443
    13  CoreFoundation                      0x03ae19fb CFRunLoopRunInMode + 123
    14  GraphicsServices                    0x052fb24f GSEventRunModal + 192
    15  GraphicsServices                    0x052fb08c GSEventRun + 104
    16  UIKit                               0x01e508b6 UIApplicationMain + 1526
    17  Spruce Dr                           0x001015ad main + 141
    18  libdyld.dylib                       0x04e6eac9 start + 1
)

Here's where I vent the UIPresentationController:

- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
    return [[STKBlurredBackgroundContentPresentationController alloc] init];
}
like image 929
codeperson Avatar asked Nov 29 '14 02:11

codeperson


People also ask

What is this uipresentationcontroller tutorial about?

In this UIPresentationController tutorial you’ll learn how to present view controllers with custom transitions and custom presentation styles. No longer will you be limited to full screen or popover presentations and the standard transition animations. You’ll start with some drab, lifeless view controller presentations and bring them to life.

How do I create custom styles in uipresentationcontroller?

Creating a custom style involves subclassing UIPresentationController and using its methods to animate any custom view onto the screen and to set the size and position of the presented view controller. The presentation controller also handles any adaptations that occur because of changes to the presented view controller’s traits.

What is the use of Direct presentation in UIViewController?

You use direct presentation to display a new view controller on top of the current one. Typically, you present view controllers when you want to implement modal interfaces, but you can also use them for other purposes. Support for presenting view controllers is built in to the UIViewController class and is available to all view controller objects.

How does the presentation controller work with the view controller?

The presentation controller also handles any adaptations that occur because of changes to the presented view controller’s traits. For information on how to define a custom presentation controller, see Creating Custom Presentations. Transition styles determine the type of animations used to display a presented view controller.


1 Answers

UIPresentationController's designated initializer must be used:

- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
    return [[STKBlurredBackgroundContentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
}

Note: I'm answering my own question here in case anyone else makes the same mistake in the future. In retrospect, it's quite clear why using the designated initializer must be utilized.

like image 51
codeperson Avatar answered Oct 04 '22 21:10

codeperson