Crash after presenting View Controller modal on iP

2019-08-05 16:19发布

问题:

I´m trying to implement a Popover for iPad and iPhone. Before iOS 9, there were different ViewController for iPad and iPhone. With iOS9 there should be a possibility to do this with a normal ViewController and different PresentationStyles? (Deployment Target is iOS 9.0) Am i right?

according to this post:

Stackoverflow answer from Daniel Galasko

I tried to implement this answer in objective c.

_mediaTypePopoverVC = [[MediaTypePopoverVC alloc] initWithProductId:PRODUCT_ID_NONE_PARENT];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_mediaTypePopoverVC];
    _popoverVC = [[UIViewController alloc] init];
    _popoverVC.modalPresentationStyle = UIModalPresentationPopover;
    _popoverVC.preferredContentSize = CGSizeMake(650.0, 364.0);
    _popoverVC.popoverPresentationController.delegate = self;


    [navigationController setViewControllers:@[_popoverVC]];

    _mediaTypePopoverVC.title = POPOVER_TITLE(mediaType.name_en, (int) [mediaList count]);
    _mediaTypePopoverVC.isCommonMediaList = YES;

    [Logic sharedInstance].currentPopoverController = _popoverVC;
    [self presentViewController:_popoverVC animated:true completion:nil];
     UIPopoverPresentationController *popover = _popoverVC.popoverPresentationController;
    if(nil != popover){
        popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
        popover.sourceView = baseButton;
        popover.sourceRect = baseButton.bounds;

    }

The crash will appear in this Line:

[self presentViewController:_popoverVC animated:true completion:nil];

My Log will give me only this:

Signal: SIGABRT (signal SIGABRT)