Bug 42014 - Application MainPage DisplayActionSheet not working
Summary: Application MainPage DisplayActionSheet not working
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-06-20 20:05 UTC by Dan Siegel
Modified: 2016-08-08 17:15 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Dan Siegel 2016-06-20 20:05:09 UTC
In 2.X version of Xamarin Forms Application.Current.MainPage.DisplayActionSheet( ... ) does not work when called after navigating from a root page. When called from a child page this results in the following warning:

Warning: Attempt to present <UIAlertController: 0x150945cf0> on <Xamarin_Forms_Platform_iOS_PageRenderer: 0x14ed86500> whose view is not in the window hierarchy!


public class MainPage {
    public MainPage()
    {
        Content = new StackLayout
        {
            new Button() { 
                Title = "Navigate", 
                Command = new Command( async () => await Navigation.PushModalAsync( new ChildPage() ) )
            },
            new Button() {
                Title = "Display ActionSheet",
                // This call will work from the MainPage
                Command = new Command( async () => await Application.Current.MainPage.DisplayActionSheet( "Title", "Cancel", "Destroy", "Foo", "Bar" ) )
            }
        }
    }
}

public class ChildPage {
    public ChildPage() 
    {
         Content = new StackLayout
         {
             new Button() {
                Title = "Display ActionSheet",
                // This call will not work
                Command = new Command( async () => await Application.Current.MainPage.DisplayActionSheet( "Title", "Cancel", "Destroy", "Foo", "Bar" ) )
            }
         }
    }
}

This currently affects all apps using the Prism Framework.
Comment 1 Rui Marinho 2016-08-08 15:09:59 UTC
The api is intended to be called from the current page in screen.
This case why won't ChildPage just do this:

await DisplayActionSheet("Title", "Cancel", "Destroy", "Foo", "Bar")

??
Comment 2 Brian Lagunas 2016-08-08 17:09:17 UTC
Can't call it from a current page because this method is being abstracted away from the page in order to be used in a MVVM application.  I assumed this was by design when the implementation of Application.MainPage changed, so I have a work around in place.
Comment 3 Rui Marinho 2016-08-08 17:15:34 UTC
Ok will close this since it's not a forms issue.