10

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

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

*** 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];
}
4

1 回答 1

22

UIPresentationController的指定初始化器必须使用:

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

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

于 2014-11-29T02:06:47.123 回答