【问题标题】:How to dismiss UIPopover from a button in the Popover with IOS 8 XCode 6 beta如何使用 IOS 8 XCode 6 beta 从 Popover 中的按钮关闭 UIPopover
【发布时间】:2014-11-18 18:32:48
【问题描述】:

我设法使用 UIPopoverPresentationController 显示弹出框,因为 UIPopoverController 在 IOS 8 中已被弃用,但现在我想通过点击弹出框中的按钮来关闭弹出框。

怎样才能解散?

【问题讨论】:

    标签: ios objective-c xcode


    【解决方案1】:

    使用 UIViewController 的 presentingViewController 属性来关闭。 例:呈现

      vc.modalPresentationStyle = UIModalPresentationPopover;
      vc.preferredContentSize  = aPreffferedSize;
      UIPopoverPresentationController *popcontroller = vc.popoverPresentationController;
      popcontroller.barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
      popcontroller.permittedArrowDirections = UIPopoverArrowDirectionAny;
      popcontroller.delegate = self;
    
      [self presentViewController:vc animated:YES completion:nil];
    

    以编程方式关闭,

      [[vc presentingViewController] dismissViewControllerAnimated:YES completion:NULL];
    

    希望这会有所帮助。

    【讨论】:

    • 这将起作用,尽管其中有一个小错误。它需要是 [[vc presentViewController] dismissViewControllerAnimated:YES completion:nil];
    【解决方案2】:

    我正在使用

    dismissViewControllerAnimated(true, completion: nil)
    

    在按钮的 IBAction 中类似的场景。

    【讨论】:

    • 你确定它会被调用吗?它是安静地失败还是出现错误?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 1970-01-01
    相关资源
    最近更新 更多