Objective c 无法在iPhone上解除UIPopoverPresentationController

Objective c 无法在iPhone上解除UIPopoverPresentationController,objective-c,iphone,uipopovercontroller,Objective C,Iphone,Uipopovercontroller,我正在实现一个CabtMidCentralViewController(苹果公司生产前的BTLE MIDI配置面板)。下面的代码是苹果的示例代码-未修改 它在iPad上工作得非常好,但在iPhone/iPod上,它会导致无法关闭的全屏视图。代码清楚地创建了一个“完成”按钮,但它没有显示在设备上 常见的答案是“您需要一个UINavigationController”,但在这段代码中有一个。所以我不确定还缺少什么 - (void)doneAction:(id)sender { [self d

我正在实现一个CabtMidCentralViewController(苹果公司生产前的BTLE MIDI配置面板)。下面的代码是苹果的示例代码-未修改

它在iPad上工作得非常好,但在iPhone/iPod上,它会导致无法关闭的全屏视图。代码清楚地创建了一个“完成”按钮,但它没有显示在设备上

常见的答案是“您需要一个UINavigationController”,但在这段代码中有一个。所以我不确定还缺少什么

- (void)doneAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)configureCentral:(id)sender
{
    CABTMIDICentralViewController *viewController [CABTMIDICentralViewController new];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];

    // this will present a view controller as a popover in iPad and modal VC on iPhone
    viewController.navigationItem.rightBarButtonItem =
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                      target:self
                                                      action:@selector(doneAction:)];

    navController.modalPresentationStyle = UIModalPresentationPopover;

    UIPopoverPresentationController *popC = navController.popoverPresentationController;
    popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
    popC.sourceRect = [sender frame];

    UIButton *button = (UIButton *)sender;
    popC.sourceView = button.superview;

    [self presentViewController:navController animated:YES completion:nil];
}

您必须实现
UIPopoverPresentationControllerDelegate
,才能查看iPhone中的PopOver。默认情况下,它将以已显示的视图控制器的样式显示

添加这段代码以将控制器显示为popover

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(nonnull UITraitCollection *)traitCollection {
    return UIModalPresentationNone;
}