【问题标题】:Xamarin.Forms iOS UIKit.UIImage ErrorXamarin.Forms iOS UIKit.UIImage 错误
【发布时间】:2016-01-07 13:19:44
【问题描述】:

我一直在使用 Xamarin.Forms 制作移动应用程序。我的一切都在 android 上运行,但是当我尝试在 iOS 上启动时出现错误:

System.Exception: Could not initialize an instance of the type 'UIKit.UIImage': the native 'initWithContentsOfFile:' method returned nil.
>It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.
....

有人知道怎么解决吗?

编辑: 这是它给我错误的代码,但我感觉是其他原因导致它:

using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;

namespace CloudClubv1._2_.iOS
{
    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");
        }
    }
}

【问题讨论】:

  • 请在您加载/分配图像的位置显示代码。
  • 任何未处理的异常都会冒泡到 Main - 但这显然不是错误的根源。我认为它是由一些在 iOS 上损坏或丢失的 Image 元素引起的,但在 Android 上有效。

标签: ios forms xamarin uikit xamarin.forms


【解决方案1】:

事实证明,错误是由于尝试将图标提供给选项卡式视图而引起的。这在 android 上运行良好,但显然在 ios 上不受支持,因此要修复错误,我只需要注释掉设置选项卡式视图的图标的行。

【讨论】:

  • 我目前遇到了这个问题。但是你是如何设法将图像设置为 iOS 版本的呢?
  • 抱歉,我记不太清了,但我认为我们的短期解决方案是暂时去掉图标,或者暂时将其设置为 android。这可以为您争取时间,以便您可以在 xamarin 的官方论坛上提问 - 他们应该能够在那里回答这个问题。
  • 我遇到了同样的问题 - 但我的问题是在将我的所有图像移动到 Resources/ 内的 Images/ 文件夹而不是图像直接在 Resources/ 中之后发生的
【解决方案2】:

确保在 IOS 项目上,将 Resources/image 属性设置为 BundledResources。在我的项目中,它们被设置为 AndroidResources,当我更正为 BundledResources 时,我开始正常工作。

【讨论】:

    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 2021-07-10
    • 2021-04-11
    • 2016-08-26
    • 1970-01-01
    • 2018-04-27
    • 2020-07-11
    • 2019-03-30
    相关资源
    最近更新 更多