1

I'm having troubles with the Xamarin iOS implementation of the Popovers.

As far as I now, they are available via the new UIPopoverPresentationController class, described in the Apple docs (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/ )

My code is something like this:

public partial class PopoverSettings : UIViewController
{
    public PopoverSettings () //: base ("PopoverSettings", null)
    {
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        View.Frame = new CoreGraphics.CGRect(0,0,100,100);
        this.PreferredContentSize = new CoreGraphics.CGSize (10, 10);
        View.BackgroundColor = UIColor.Red;
    }
}

And I try to create it from

var myPop = new PopoverSettings();
myPop.ModalInPopover = true;
myPop.ModalPresentationStyle = UIModalPresentationStyle.Popover;
var pc = (UIPopoverPresentationController)myPop.PresentationController;
pc.SourceView = navigation;
pc.SourceRect = new CGRect(0,0,100,100);
this.PresentViewController(myPop, true, null);          

The result is working, but I get a FULL SCREEN View Controller, not a "Popover" component!

Does anybody knows why it goes like this? Thanks!

Ziba Leah
  • 2,484
  • 7
  • 41
  • 60
  • 2
    Are you trying this on iPad or iPhone? Have a look at this: http://stackoverflow.com/questions/25319179/uipopoverpresentationcontroller-on-ios-8-iphone – pnavk May 09 '16 at 16:12
  • Yes, but that solution includes Multiple Inheritance (from UIViewController and UIPopoverPresentationControllerDelegate) that is not supported in .NET – Ziba Leah May 09 '16 at 17:34
  • To get around that limitation, you can implement `IUIPopoverControllerDelegate` instead and just override the appropriate delegate methods. https://developer.xamarin.com/api/type/MonoTouch.UIKit.IUIPopoverControllerDelegate/ – pnavk May 09 '16 at 17:49
  • Even trying to implement the IUIPopoverPresentationControllerDelegate it does not work. Every property I could be interested in is "read only" and the event is not triggered event if I set Controller.PopoverPresentationController.Delegate = this – Ziba Leah May 11 '16 at 07:45
  • What is "navigation" in the second code block above? – wildbagel Jan 17 '18 at 16:09

1 Answers1

1

If you are implementing this on the iPhone, the framework will automatically change your PresentationStyle to Fullscreen. To prevent this you have to implement the IUIPopoverPresentationControllerDelegate interface callback 'adaptivePresentationStyleForPresentationController'.

[Export("adaptivePresentationStyleForPresentationController:")]
public UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
    return UIModalPresentationStyle.None;
}

Then you have to make sure you set the delegate property of the PresentationController to the reference of the class where you implemented the callback.

pc.delegate = this;

The framework will now call your callback and you can force it to make it a popover.

Kenneth
  • 3,957
  • 8
  • 39
  • 62
Frank008
  • 11
  • 2