【发布时间】:2016-09-23 12:03:30
【问题描述】:
我有一个 Xamarin 项目,我已经从事了相当长的一段时间。 但是突然打开主界面就空白了。在 iOS 模拟器和我的 iOS 设备上。
应用构建时没有错误。我得到了启动画面,然后只是一个白色的空白屏幕。
我在带有 MVVMCross 和情节提要的 Visual Studio 15 中使用 Xamarin。
我尝试了以下方法:
- 重置 iOS 模拟器
- Visual Studio 中的已清理解决方案
- 尝试将另一个故事板作为主界面
有什么想法吗?
编辑:这是我的 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();
}
}
}
【问题讨论】:
-
您的 AppDelegate 方法看起来如何?你能发布一些最重要的方法吗?
-
我的 AppDelegate.cs 添加到顶部。
-
您的 AppStart 是什么样的?您的设置是什么样的?
-
这些也加在上面
标签: ios xamarin.ios mvvmcross