您好,我有一个应用程序我正在使用Xamrian iOS本机和Xamrian Forms中的一部分,我尝试做的就是当用户点击我本机应用程序中的contectbttn时它打开了来自CountySelect类的xamrian。我在应用程序崩溃后单击设备上的按钮时收到此错误:
System.InvalidOperationException: call Forms.Init() before this
这里是按下按钮的原生Xamrian iOS代码:
using System;
using UIKit;
using CoreGraphics;
using Xamarin.Forms;
namespace App.iOS
{
public partial class HomeView : UIViewController
{
public HomeView(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
contactbttn.TouchUpInside += (sender, e) => {
var secondViewController = App.GetSecondPage().CreateViewController();
NavigationController.PushViewController(secondViewController, true);
};
}
}
}
这是我的app.cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace App
{
public class App : Application
{
public static Page GetSecondPage()
{
var formsPage = new NavigationPage(new CountySelect());
return formsPage;
}
public App()
{
// The root page of your application
//MainPage = new MainPage();
MainPage = new NavigationPage(new CountySelect());
}
protected override void OnStart()
{
// Handle when your app starts
}
public static object CountySelect()
{
throw new NotImplementedException();
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
编辑此处的AppDelegate代码:
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Foundation;
using UIKit;
using System.IO;
using Xamarin.Forms.Platform.iOS;
namespace App.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
public override UIWindow Window
{
get;
set;
}
// This method is invoked when the application is about to move from active to inactive state.
// OpenGL applications should use this method to pause.
public override void OnResignActivation(UIApplication application)
{
}
// This method should be used to release shared resources and it should store the application state.
// If your application supports background exection this method is called instead of WillTerminate
// when the user quits.
public override void DidEnterBackground(UIApplication application)
{
}
// This method is called as part of the transiton from background to active state.
public override void WillEnterForeground(UIApplication application)
{
}
// This method is called when the application is about to terminate. Save data, if needed.
public override void WillTerminate(UIApplication application)
{
}
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Forms.Init();
return true;
}
}
}
我不知道如何解决这个错误我试过谷歌搜索错误而没有运气:/
任何帮助都会很棒
提前致谢!