大佬教程收集整理的这篇文章主要介绍了ios - PageRenderer xamarin 表单中的 ViewWillAppear 中的对象引用崩溃,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我们为 xamarin 表单 ios 中的导航返回按钮自定义工具栏菜单。我在 appcenter 中崩溃了。 ToolbarMenuCustomrenderer.VIEwWillAppear(System.Boolean 动画) SIGABRT:未将对象引用设置为对象的实例
下面的代码片段:
public overrIDe voID VIEwWillAppear(bool animated)
{
base.VIEwWillAppear(animated);
CustomToolbarContentPage page = Element as CustomToolbarContentPage;
if (page == null)
return;
#region for soft BACk button
UIVIEwController root = NavigationController.topVIEwController;
if (!page.NeedOverrIDeSoftBACkbutton)
return;
String title = "<" + (String.IsNullOrEmpty(NavigationPage.GetBACkbuttontitle(Element)) ? "" : NavigationPage.GetBACkbuttontitle(Element));
root.NavigationItem.SetleftbarbuttonItem(
new UIbarbuttonItem(title,UIbarbuttonItemStyle.Plain,(sender,args) =>
{
page.onSoftBACkbuttonpressed();
}),truE);
#endregion
}
如何在 xamarin 形式的 ios 中解决这个问题?
我使用您的代码创建了一个示例应用并且运行良好,您可以检查下面的代码,看看是否遗漏了什么:
新页面:
namespace My_Forms_test.Views
{
public partial class NewPage2 : ContentPage
{
public NewPage2()
{
InitializeComponent();
}
public void OnSoftBACkButtonPressed()
{
Navigation.PopToRootAsync();
}
}
}
自定义渲染器:
[assembly:ExportRenderer(typeof(NewPage2),typeof(MyPageRenderer))]
namespace My_Forms_test.iOS
{
public class MyPageRenderer:PageRenderer
{
public MyPageRenderer()
{
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
NewPage2 page=Element as NewPage2;
UIViewController root = NavigationController.TopViewController;
String title = "<" + (String.IsNullOrEmpty(NavigationPage.GetBACkButtontitle(Element)) ? " " : NavigationPage.GetBACkButtontitle(Element));
root.NavigationItem.SetLeftBarButtonItem(
new UIBarButtonItem(title,UIBarButtonItemStyle.Plain,(sender,args) =>
{
page.onSoftBACkButtonPressed();
Console.WriteLine("This method is trigged"); }),truE);
}
}
以下是截图:
你也可以参考这个文档https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/contentpage
以上是大佬教程为你收集整理的ios - PageRenderer xamarin 表单中的 ViewWillAppear 中的对象引用崩溃全部内容,希望文章能够帮你解决ios - PageRenderer xamarin 表单中的 ViewWillAppear 中的对象引用崩溃所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。