Xamarin.Forms iOS UIKit.UIImage Error

2019-08-09 06:08发布

问题:

I've been working with making a mobile app using Xamarin.Forms. I have everything working on android, but when I try to launch on iOS I get the error:

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.
....

Does anyone know how to solve this?

Edit: Here is the code it gives me the error on, but I have the feeling something else is causing it:

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");
        }
    }
}

回答1:

So it turns out the error was being caused by trying to give an icon to a tabbed view. This works fine on android, but apparently on ios it isn't supported, so to fix the error I just had to comment out the line where the an icon for the tabbed view was set.



回答2:

Make sure on IOS project, set Resources/image properties to BundledResources. In my project they were set to AndroidResources, when I corrected to BundledResources my start working fine.