我有一个Xamarin项目,我已经工作了很长一段时间。 但是当我打开它时,主界面突然变成空白。在iOS模拟器和我的iOS设备上。
应用构建时没有错误。我得到了我的闪屏,然后只是一个白色的空白屏幕。
我在Visual Studio 15中使用Xamarin与MVVMCross和故事板。
我尝试了以下内容:
有什么想法吗?
编辑:这是我的AppDelegate.cs文件:
using Foundation;
using MvvmCross.Core.ViewModels;
using MvvmCross.iOS.Platform;
using MvvmCross.Platform;
using UIKit;
using Tjenester.Touch.Util;
namespace Tjenester.Touch
{
[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
UIWindow _window;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
_window = new UIWindow(UIScreen.MainScreen.Bounds);
var setup = new Setup(this, _window);
setup.Initialize();
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
_window.MakeKeyAndVisible();
MessageService.Initialize(this);
return true;
}
}
}
这是我的CustomAppStart.cs:
using System;
using System.Threading.Tasks;
using Tjenester.Core.Helpers;
using Tjenester.Core.Services.Authentication;
using Tjenester.Core.ViewModels;
using Tjenester.Core.ViewModels.ViewModelParameters;
using Xamarin.Auth;
using Tjenester.Core;
using System.Threading;
using MvvmCross.Core.ViewModels;
/// <summary>
/// Custom Application start procedure to be fed to MvvmCross.
/// If we already have Username and Password, try login and proceed to the page.
/// TODO refactor when azure and google are added
/// </summary>
public class CustomAppStart : MvxNavigatingObject, IMvxAppStart
{
public void Start(object hint = null)
{
ShowViewModel<LoginViewModel>(new LoginPageParameters() {TryLogin = true});
}
}
这是我的Setup.cs:
using UIKit;
using Tjenester.Core.Helpers;
using Foundation;
using Tjenester.Core.Services.Media;
using Tjenester.Touch.Services;
using Tjenester.Core.Services.Storage;
using Tjenester.Core.Services.Scripting;
using Tjenester.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Tjenester.Core.Services.Http;
using MvvmCross.Core.ViewModels;
using MvvmCross.iOS.Platform;
using MvvmCross.Localization;
using MvvmCross.Platform;
using MvvmCross.Platform.Platform;
using MvvmCross.Platform.Plugins;
using Tjenester.Touch.Services.Http;
using Tjenester.Touch.Services.Storage;
namespace Tjenester.Touch
{
public class Setup : MvxIosSetup
{
private readonly UIWindow _win;
private readonly MvxApplicationDelegate _del;
public Setup(MvxApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
_del = applicationDelegate;
_win = window;
}
protected override IMvxApplication CreateApp()
{
UIContext.SynchronizationContext = SynchronizationContext.Current;
if (NSLocale.PreferredLanguages.Length > 0) {
var pref = NSLocale.PreferredLanguages [0];
Settings.Language = pref.Substring (0, 2);
}
//Mvx.LazyConstructAndRegisterSingleton<IFileUploadService, TouchFileUploadService>();
Mvx.LazyConstructAndRegisterSingleton<IHttpClientFactory, HttpClientFactory>();
Mvx.LazyConstructAndRegisterSingleton<IStorageService, StorageService>();
Mvx.LazyConstructAndRegisterSingleton<IPicturePickerService, TouchPicturePickerService>();
return new Core.App();
}
protected override IEnumerable<System.Reflection.Assembly> ValueConverterAssemblies
{
get
{
var toReturn = base.ValueConverterAssemblies.ToList();
toReturn.Add(typeof(MvxLanguageConverter).Assembly);
return toReturn;
}
}
protected override IMvxPluginConfiguration GetPluginConfiguration(Type plugin)
{
if (plugin == typeof(Tjenester.Core.Services.Scripting.PluginLoader))
{
return new MvxScriptServiceConfiguration()
.UseDefaultScriptBindings()
;
}
return base.GetPluginConfiguration(plugin);
}
protected override IMvxTrace CreateDebugTrace()
{
return new MvxDebugTrace();
}
}
}
答案 0 :(得分:0)
您是否可以尝试手动初始化MvxIosViewPresenter以获取更多信息?
因此,您必须使用以下行(ApplicationDelegate.cs):
_window = new UIWindow(UIScreen.MainScreen.Bounds);
var presenter = new MvxIosViewPresenter(this, _window);
var setup = new Setup(this, presenter);
setup.Initialize();
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
var rootViewController = new FirstView(); // You need to have created this ViewController
_window.RootViewController = rootViewController;
_window.MakeKeyAndVisible();
return true;
如果这适合您,那么这意味着您的故事板尚未正确创建。在故事板上设计的FirstViewController不知道实现MvxViewController的类FirstViewViewController的“Code”版本。
想要那个bash,看看它是怎么回事?这不是一个优雅的解决方案,但可以提供一些见解。