Zac*_*Zac 6 c# xamarin.ios ios
这真的让我陷入困境。我为 Visual Studio 安装了 Xamarin,创建了一个空项目并连接到我的 Mac。我模拟 iPhone 并收到此错误
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch
Run Code Online (Sandbox Code Playgroud)
这是由在Main.cs类中调用 UIApplication.Main 引起的
using UIKit;
namespace testapp
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我绝对无处可去-以前有人遇到过吗?
我遇到了同样的错误,在我的情况下,我在设置 MainPage 之前运行了 async/await 方法。所以,我只是移动了 MainPage = new MainPage(); 在 InitializeComponent() 之后;现在可以使用了。
它接缝AppDelegate在您的项目中未正确实施。iOS 需要知道什么是根控制器 (UIViewController) 来初始化应用程序。该AppDelegate班负责设置它。这将在应用程序初始化时添加一个空的视图控制器:
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
window.RootViewController = new UIViewController ();
window.MakeKeyAndVisible ();
return true;
}
}
Run Code Online (Sandbox Code Playgroud)