无法创建“FWSImageRepo”类型的本地实例。本地类尚未加载
我试图链接内部使用AFNetworking
的本机iOS框架,我最初将其构建为原型,将我公司的部分ObjC IP移植到可与Xamarin链接在将来。无法创建“FWSImageRepo”类型的本地实例。本地类尚未加载
我开始通过使加载使用AFNetworking小猫成的UIImageView一个简单的类
头文件
#import <UIKit/UIKit.h>
@interface FWSImageRepo : NSObject
+(UIImageView *)imageViewFromURLString:(NSString *)urlString;
@end
实施
@implementation FWSImageRepo
+(UIImageView *)imageViewFromURLString:(NSString *)urlString{
UIImageView *imageView = [[UIImageView alloc] init];
NSURL *imageUrl= [NSURL URLWithString:@"http://www.pets4homes.co.uk/images/articles/1334/large/6-health-issues-to-watch-for-in-young-kittens-52f62cff5cabb.jpg"];
if(imageUrl != nil) {
[imageView setImageWithURL:imageUrl];
}
return imageView;
}
@end
我创建了一个框架编译器目标和我已经将框架复制到Xamarin iOS项目中。我用记号笔目的生成以下
// @interface FWSImageRepo : NSObject
[BaseType(typeof(NSObject))]
interface FWSImageRepo
{
// +(UIImageView *)imageViewFromURLString:(NSString *)urlString;
[Static]
[Export("imageViewFromURLString:")]
UIImageView ImageViewFromURLString(string urlString);
}
所有这些被链接的指示在binding project
绑定,框架被链接为本地参考,并绑定项目是由一个单一页面Xamarin iOS应用引用。
现在仅仅是初始化var fwrepo = new FWSImageRepo();
这个类就表示我完全不喜欢这个框架。即使我没有链接绑定项目中的框架,错误也不会改变
Could not create an native instance of the type 'FWSImageRepo': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
任何理由检查发生了什么?我已经尝试了一切,并在网上搜索了我的精力。只要我搜索过,没有任何这方面的要求的例子,几乎没有任何方向。我已经尝试了其他面临相同问题的解决方案。我如何寻找我出错的地方?
下面是我创建https://drive.google.com/open?id=0B2f9RlRxZKoZcElIRkpLZnF6WVU
无法创建类型“FWSImageRepo”的原生性实例项目链接:原生类尚未加载。通过将ObjCRuntime.Class.ThrowOnInitFailure设置为false,可以忽略此情况。
这表明相关的本地库尚未加载。我会通过文档走:
https://developer.xamarin.com/guides/ios/advanced_topics/native_interop/
,以确定您的项目设置没有在本地库加载。
这并不完全解决问题,但由于@克里斯使我意识到,这是一个问题与不加载类,解决方案实际上是在修改了iOS构建设置符合以下条件的选择
我仍然只能静态访问方法,如下:
// @interface FWSImageRepo : NSObject
[BaseType(typeof(NSObject))]
public interface FWSImageRepo
{
// +(UIImageView *)imageViewFromURLString:(NSString *)urlString;
[Static]
[Export("imageViewFromURLString:")]
UIImageView ImageViewFromURLString(string urlString);
}
和访问它像这样
var imageview = FWSImageRepo.ImageViewFromURLString("");
任何想法,为什么我不能使用它作为一个实例(我删除了[静态]属性?
是的,这听起来对我来说也是如此,但我无法确定问题出在哪里。感谢您的链接。 –