DisplayActionSheet not showing

2019-08-07 12:14发布

问题:

I'm using MessagingCenter to signal a MasterDetailPage from my model.

private void ShowActionSheet(object sender, IEnumerable<string> hosts)
{
    Device.BeginInvokeOnMainThread(async () =>
    {
        // Works
        await DisplayAlert("Testing!", "Some text", "OK");

        // Does not work
        await DisplayActionSheet("Test", "Cancel", "Destroy", new[] {"1","2"});
    }
}

When calling DisplayActionSheet I get the following warning:

Warning: Attempt to present <UIAlertController: 0x7e737aa0> on <Xamarin_Forms_Platform_iOS_NavigationRenderer: 0x7e4b31a0> whose view is not in the window hierarchy!

There's a "Please wait"-modal on top of the MasterDetailPage. It works without the modal, but that's not really an acceptable solution.

Any tips or pointers will be appreciated.


UPDATE: I've moved DisplayActionSheet to the modal as a last resort. I still fear that this issue is iOS 8.2 related.

回答1:

change your code:

Device.StartTimer(new TimeSpan(0, 0, 0, 0, 500), ShowActionSheet);

async Task<bool> ShowActionSheet()
{
    await DisplayActionSheet("Test", "Cancel", "Destroy", new[] {"1","2"});
    return false;
}