【问题标题】:Blank screen on iOSiOS 上的空白屏幕
【发布时间】:2016-09-23 12:03:30
【问题描述】:

我有一个 Xamarin 项目,我已经从事了相当长的一段时间。 但是突然打开主界面就空白了。在 iOS 模拟器和我的 iOS 设备上。

应用构建时没有错误。我得到了启动画面,然后只是一个白色的空白屏幕。

我在带有 MVVMCross 和情节提要的 Visual Studio 15 中使用 Xamarin。

我尝试了以下方法:

  1. 重置 iOS 模拟器
  2. Visual Studio 中的已清理解决方案
  3. 尝试将另一个故事板作为主界面

有什么想法吗?

编辑:这是我的 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


【解决方案1】:

您能否尝试手动初始化 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 的“代码”版本。

想来一场狂欢,看看进展如何?这不是一个优雅的解决方案,但可以提供一些见解。

【讨论】:

  • 我发现了导致此错误的原因。如果我取消选中它加载的情节提要上的“自动布局”,但现在当然不成比例。故事板的制作方式是否有问题会导致这种情况?
  • 这听起来很奇怪。我的空白起始屏幕通常是没有在情节提要视图上正确设置类名。
猜你喜欢
  • 1970-01-01
  • 2018-03-18
  • 2014-10-13
  • 2018-11-14
  • 2021-04-26
  • 1970-01-01
  • 2015-04-18
  • 2019-09-22
  • 2019-03-17
相关资源
最近更新 更多