Xamarin.Forms警告:尝试在*不在iOS图像/手势识别器的窗口层次结构中显示其视图上的* [英] Xamarin.Forms Warning: Attempt to present * on * whose view is not in the window hierarchy with iOS image/gesture recogniser
问题描述
我有一个模态导航页面,上面有一个像按钮一样的图像;
I have a modal Navigation page with an image which acts like a button;
<Image Source ="share.png" HeightRequest="32" WidthRequest="32">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="On_Share" />
</Image.GestureRecognizers>
</Image>
以及背后的方法;
async void On_Share(object sender, EventArgs e)
{
if (CrossConnectivity.Current.IsConnected)
{
var message = "Share this";
var title = "Share";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title}, new ShareOptions { ExcludedUIActivityTypes = new[] { ShareUIActivityType.PostToFacebook } });
}
else
{
NoInternetLabel.IsVisible = true;
}
}
当我尝试单击共享图像/按钮时出现错误.我已经在On_Share方法的第一行中添加了断点.他们没有被击中.
I'm getting the error when I try to click on the share image/button. I've put breakpoints into the first line of the On_Share method & they're not being hit.
Warning: Attempt to present <UIActivityViewController: 0x141b60f70> on <Xamarin_Forms_Platform_iOS_ModalWrapper: 0x1419a0920> whose view is not in the window hierarchy!
请注意,这在Android上工作正常,我仅在iOS中看到问题.我不确定发生了什么-单击图像时,我没有尝试显示任何其他窗口或任何其他内容.无论如何,该错误将在进程到达On_Share方法的开始之前出现.我在这里想念什么?
Please note this works fine in Android, I'm only seeing issues in iOS. I'm not sure what is going on - I'm not trying to present any other windows or anything when I click the image. Regardless, the error appears before the process reaches the beginning of the On_Share method. What am I missing here?
该方法现在确实被点击了,但我仍然遇到错误.它必须试图发送共享表并失败...
The method does get hit now, and I'm still getting the error. It must be trying to send up the share sheet and failing...
推荐答案
Share插件最后出现了问题-我们通过使部分代码递归来解决了该问题.
There was a problem with the Share plugin in the end - we resolved it by making part of the code recursive.
GetVisibleViewController过去看起来像这样;
the GetVisibleViewController used to look like this;
UIViewController GetVisibleViewController()
{
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
if (rootController.PresentedViewController == null)
return rootController;
if (rootController.PresentedViewController is UINavigationController)
{
return ((UINavigationController)rootController.PresentedViewController).VisibleViewController;
}
if (rootController.PresentedViewController is UITabBarController)
{
return ((UITabBarController)rootController.PresentedViewController).SelectedViewController;
}
return rootController.PresentedViewController;
}
需要循环搜索以找到顶部的UIViewController;
whereas it needed to cycle through to find the top UIViewController;
UIViewController GetVisibleViewController(UIViewController controller = null)
{
controller = controller ?? UIApplication.SharedApplication.KeyWindow.RootViewController;
if (controller.PresentedViewController == null)
return controller;
if (controller.PresentedViewController is UINavigationController)
{
return ((UINavigationController)controller.PresentedViewController).VisibleViewController;
}
if (controller.PresentedViewController is UITabBarController)
{
return ((UITabBarController)controller.PresentedViewController).SelectedViewController;
}
return GetVisibleViewController(controller.PresentedViewController);
}
我提出了这个问题,并在 github
I've raised the issue and submitted a pull request on the github
这篇关于Xamarin.Forms警告:尝试在*不在iOS图像/手势识别器的窗口层次结构中显示其视图上的*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!