简体   繁体   中英

Nested alert messages in Xamarin iOS using UIAlertController

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM