简体   繁体   English

从路径加载笔尖

[英]Loading a nib from a path

Currently I've been loading nibs programmatically in my app using [NSBundle mainBundle] loadNibNamed: . 目前我一直在使用[NSBundle mainBundle] loadNibNamed:在我的应用程序中以编程方式加载[NSBundle mainBundle] loadNibNamed: All I want to do is just contain all my nibs in a subfolder (and their referenced images), but it seems near impossible to load these. 我想要做的只是在子文件夹中包含我的所有笔尖(及其引用的图像),但似乎几乎不可能加载它们。 loadNibNamed doesn't allow a path to be specified. loadNibNamed不允许指定路径。 I've done a ton of searching and can't find any suitable way. 我做了很多搜索,找不到合适的方法。 Everything else I've tried gives an exception. 我尝试过的其他所有内容都有例外。 I've tried loading the data from file and unarchiving it, but it says it's an incomprehensible archive. 我已经尝试从文件中加载数据并取消归档,但它说它是一个难以理解的存档。 UINib has the same problem as NSBundle . UINibNSBundle有同样的问题。

There has to be a way to specify the file path, just like loading any other file. 必须有一种方法来指定文件路径,就像加载任何其他文件一样。

I want the final contents to be an NSArray just like loadNibNamed: returned. 我希望最终内容是一个NSArray ,就像loadNibNamed:

Any insight would be helpful. 任何见解都会有所帮助。

The closest I got was using [NSBundle bundleWithPath:] and specifiying the fullpath. 我得到的最接近的是使用[NSBundle bundleWithPath:]并指定完整路径。 It says the path is not yet loaded, and throws and exception. 它表示路径尚未加载,并抛出异常。 Why is it not loaded? 为什么没装?

I think you are getting "not yet loaded" because you are not loading the bundle [bundle load]. 我认为你没有加载“尚未加载”,因为你没有加载bundle [bundle load]。 Also check for Name case-sensitivity because simulator is generally case-insensitive and Device is not. 还要检查名称区分大小写,因为模拟器通常不区分大小写,而Device不是。 Try this and see how you go. 试试这个,看看你怎么样。

Regards, Ravi 此致,拉维

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM