xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.47k stars 512 forks source link

UIAlertController.PopoverPresentationController returns null #10329

Closed hungnguyenepiserver closed 3 years ago

hungnguyenepiserver commented 3 years ago
  1. Create an UIAlertController but display as Popover Menu on iPad follow xamarin doc: https://docs.microsoft.com/en-us/xamarin/ios/user-interface/controls/alerts

// Create a new Alert Controller UIAlertController actionSheetAlert = UIAlertController.Create("Action Sheet", "Select an item from below", UIAlertControllerStyle.ActionSheet);

// Add Actions
actionSheetAlert.AddAction(UIAlertAction.Create("OK",UIAlertActionStyle.Default, (action) => Console.WriteLine ("Item One pressed.")));

actionSheetAlert.AddAction(UIAlertAction.Create("custom button 1",UIAlertActionStyle.Default, (action) => Console.WriteLine ("Item Two pressed.")));

actionSheetAlert.AddAction(UIAlertAction.Create("Cancel",UIAlertActionStyle.Cancel, (action) => Console.WriteLine ("Cancel button pressed.")));

// Required for iPad - You must specify a source for the Action Sheet since it is
// displayed as a popover
UIPopoverPresentationController presentationPopover = actionSheetAlert.PopoverPresentationController;
if (presentationPopover!=null) {
    presentationPopover.SourceView = this.View;
    presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up;
}

// Display the alert
this.PresentViewController(actionSheetAlert,true,null);
  1. actionSheetAlert.PopoverPresentationController return null

Expected Behavior

actionSheetAlert.PopoverPresentationController not null

Actual Behavior

actionSheetAlert.PopoverPresentationController is null

Environment

Xamarin 7.0 Build on Emulator any iPad ios 14.3

Example Project (If Possible)

https://github.com/xamarin/docs-archive/blob/master/Recipes/ios/standard_controls/alertcontroller/AlertControllerSample/AlertControllerSampleViewController.cs

tj-devel709 commented 3 years ago

Hello! Thank you very much for your feedback.

It appears that UIActionSheet has been deprecated since iOS 8. Try using UIAlertController which has replaced UIAlertController. You can find the documentation here.

If this does not work for you, feel free to reopen this issue. Thank you!

hungnguyenepiserver commented 3 years ago

Hello! Thank you very much for your feedback.

It appears that UIActionSheet has been deprecated since iOS 8. Try using UIAlertController which has replaced UIAlertController. You can find the documentation here.

If this does not work for you, feel free to reopen this issue. Thank you!

Hello TJ @tj-devel709 , I've edited the description for more detail. I'm using UIAlertController as your comment but the UIPopoverPresentationController .PopoverPresentationController from is null