Reputation: 8867
Trying to create a nested dialogues in Xamarin iOS - idea is to show detailed exception information. I'm new to iOS development. I'd like to know if I'm on the right path to begin with? And what am I missing?
In the example below when user clicks ShowDetailedException
additional popup dialogue should appear
----------------------
|Error |
|Something went wrong|
|____________________|
|ShowDetailedException|Ok|
-----------------------
|Title |
|Exception(StackTrace)|
-----------------------
|OK button |
-----------------------
I'm trying to implement this in UIViewController
class.
What I have so far:
public void ShowErrorMessage(Exception ex)
{
bool isDebug;
#if DEBUG
isDebug = true;
#endif
var alert = UIAlertController.Create("Error", "Something went wrong", UIAlertControllerStyle.Alert);
alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, null));
if (isDebug)
{
var infoAction = UIAlertAction.Create("Info", UIAlertActionStyle.Default, action => ShowError(ex));
alert.AddAction(infoAction);
}
SetupPopover(alert, this.View);
this.PresentViewController(alert, animated: true, completionHandler: null);
}
private void SetupPopover(UIAlertController alertController, UIView sourceView)
{
var popover = alertController.PopoverPresentationController;
if (popover != null)
{
popover.SourceView = sourceView;
popover.SourceRect = sourceView.Bounds;
}
}
I've managed to implement this using UIAlertView
but since iOS 8 uses UIAlertController
, I have to use that.
Currently my alert.PopoverPresentationController
is null...
Any help and ideas will be appreciated.
Upvotes: 0
Views: 1163
Reputation: 938
alertController.PopoverPresentationController
will only return an instance if it's running on an iPad or IPhone 6+ (I think). If it's running on a compact device, like the phones, NULL will be returned.
If you say you having it working with UIAlertView
, then it should still execute on iOS 8.
Upvotes: 1