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 on iPad #10333

Closed hungnguyenepiserver closed 3 years ago

hungnguyenepiserver commented 3 years ago

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); 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

Thank you very much for your feedback. I am able to recreate the results you are getting and will look into this issue!

dalexsoto commented 3 years ago

The broader developer community would be the best and quickest place for additional troubleshooting help on this issue. Posting a question on Stack Overflow [0] or the .NET on Q&A Forum [1] would be the best next step.

[0] https://stackoverflow.com/questions/tagged/xamarin [1] https://docs.microsoft.com/en-us/answers/products/dotnet

Investigation by the Xamarin team in the bug tracker for an issue like this would usually require that the reporter include additional background info to hint that Xamarin is behaving differently compared to Xcode via an objective-c project and its equivalent Xamarin project.

Xamarin.iOS is just a thin layer on top of the native SDKs so this is very unlikely to be a bug in Xamarin.iOS but a behavioral change in UIKit since that sample code got written.