Daniel Z.
Daniel Z.

Reputation: 324

Xamarin Ios PopoverController unhandled exception

Does anyone know why this code won't work. Just added a popovercontroller to the hello world example from xamarin. I always get a unhandled exception but there is no additional information in the output.

public class MyViewController : UIViewController
    {
        UIButton button;
        int numClicks = 0;
        float buttonWidth = 200;
        float buttonHeight = 50;
        UIPopoverController popover;


    public MyViewController()
    {
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        View.Frame = UIScreen.MainScreen.Bounds;
        View.BackgroundColor = UIColor.White;
        View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

        button = UIButton.FromType(UIButtonType.RoundedRect);

        button.Frame = new RectangleF(
            View.Frame.Width / 2 - buttonWidth / 2,
            View.Frame.Height / 2 - buttonHeight / 2,
            buttonWidth,
            buttonHeight);

        button.SetTitle("Click me", UIControlState.Normal);
        button.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin |
        UIViewAutoresizing.FlexibleBottomMargin;

        var content = new UIViewController();
        popover = new UIPopoverController(content);
        popover.SetPopoverContentSize(new SizeF(80, 80), true);


        button.TouchUpInside += (object sender, EventArgs e) =>
        {

            popover.PresentFromRect(new RectangleF(80, 80, 80, 80), View, UIPopoverArrowDirection.Left, true);
        };



        View.AddSubview(button);
    }

}

Thanks for any respond.

Upvotes: 0

Views: 604

Answers (1)

Dan Miranda
Dan Miranda

Reputation: 161

It is possible that you are testing this code on an iPhone project, UIPopoverController does not work with iPhone.

To see it working you should change the setting Devices to iPad in your Info.plist file.

I tested the class in an iPad simulator and it works.

Upvotes: 1

Related Questions