Cocoa - loadNibNamed:owner:topLevelObjects: from loaded bundle

﹥>﹥吖頭↗ 提交于 2019-12-01 08:38:29

It is not clear to me exactly what you're asking - where is the "loading class" that is not in your application's bundle coming from, and what exactly do you mean by "loading class"?

Maybe the following will help:

loadNibNamed:owner:topLevelObjects: is an instance method and loads from the bundle the instance represents.

In your sample the instance you've used you obtain via [NSBundle mainBundle], so the nib is loaded from the applications main bundle.

There is no "current bundle" concept, but you can obtain an NSBundle instance representing other bundles, e.g. with NSBundle's class method bundleWithURL. So to load a nib from a different bundle first create an NSURL that references the bundle, then create an NSBundle based on that, and finally load the nib.

HTH

Addendum - After Question Updated

From the deprecated +loadNibName:owner: method's description of owner:

If the class of this object has an associated bundle, that bundle is searched for the specified nib file; otherwise, this method looks in the main bundle.

This is what you need to replicate when using -loadNibNamed:owner:topLevelObjects:. The method you need is NSBundle's bundleForClass: which returns the NSBundle object that dynamically loaded a class.

So in your Plugin class you should be able to find the bundle it was loaded from with [NSBundle bundleForClass:[self class]] and then call -loadNibNamed:owner:topLevelObjects: on that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!