UIPopoverPresentationController在iPhone上不能被解雇。

问题描述 投票:2回答:1

我正在实现一个CABTMIDICentralViewController(苹果预制的BTLE MIDI配置面板)。下面的代码是苹果公司的示例代码--未经修改。

它在iPad上可以完美地工作,但在iPhoneiPod上,它的结果是一个无法关闭的全屏视图。这段代码清楚地创建了一个 "完成 "按钮,但在设备上却没有显示。

通常的答案是 "你需要一个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];
}
objective-c iphone uipopovercontroller
1个回答
0
投票

你将不得不实现 UIPopoverPresentationControllerDelegate 来查看iPhone中的popovers。默认情况下,它将以已经呈现的视图控制器的样式呈现。

添加这段代码,以弹出式控制器的方式呈现。

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(nonnull UITraitCollection *)traitCollection {
    return UIModalPresentationNone;
}
© www.soinside.com 2019 - 2024. All rights reserved.