ios - 从 iPhone 中的 UIBarButtonItem 呈现弹出框

标签 ios objective-c iphone uiviewcontroller uipopovercontroller

我想在 UIBarButtonItem 中将 View Controller 显示为 iPhone 中的弹出窗口

我在按钮的操作上编写了以下代码。

-(IBAction)showAvailableCategory:(UIButton *)sender
{
    CategoryPopup *categoryPopupViewController = [[CategoryPopup alloc]init];
    UIPopoverPresentationController *popOverCat  = categoryPopupViewController.popoverPresentationController;
    categoryPopupViewController.preferredContentSize = CGSizeMake(138, 122);
    popOverCat.delegate = self;
    popOverCat.sourceView = sender;
    popOverCat.sourceRect = sender.bounds;
    popOverCat.permittedArrowDirections = UIPopoverArrowDirectionAny;
    [self presentViewController:categoryPopupViewController animated:YES completion:nil];
}

我做了我的CategoryPopup作为 xib 中的自由格式而且我正在实现下面的委托(delegate)方法
-(UIModalPresentationStyle) adaptivePresentationStyleForPresentationController: (UIPresentationController * ) controller
{
    return UIModalPresentationNone;
}

但它不是作为弹出窗口出现而是全屏出现,有解决方法吗?

最佳答案

您只忘记了一项设置,请在 categoryPopupViewController 之后添加的初始化:

categoryPopupViewController.modalPresentationStyle = UIModalPresentationPopover;

关于ios - 从 iPhone 中的 UIBarButtonItem 呈现弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41691553/

相关文章:

ios - 在 Collection View 中设置图像和名称 swift 5

ios - 以编程方式快速创建带有约束的 UIbutton

ios - NavigationLink 不适用于 SwiftUI 中列表内的 ScrollView

objective-c - 如何向 "hidden"类添加类别

iphone - UICollectionView 在不同的批量更新中累积动画

iphone - 在 iphone 界面生成器上使用圆角边框设计 'fieldset'

ios - 推证书撤销

ios - Iphone 4 和 Iphone 5 中的 UIView 问题

objective-c - NSlogging 和 NSString 难题

iphone - 显示图像和字符串的 UIPIckerView