使用自定义UIPresentationController子类呈现视图控制器时出现神秘崩溃

时间:2014-11-29 02:06:47

标签: ios uipresentationcontroller

我在尝试使用自定义UIViewController子类进行自定义演示UIPresentationController时遇到iOS 8.1(设备和模拟器)崩溃。

引发的异常将以下内容打印到控制台:

*** 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
)

在这里我发泄UIPresentationController

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

1 个答案:

答案 0 :(得分:22)

必须使用

UIPresentationController指定的初始值设定项:

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

注意:我在这里回答我自己的问题,以防其他人在将来犯同样的错误。回想起来,为什么必须使用指定的初始化程序非常清楚。