Nib 文件无法从主包中按名称加载

发布于 2024-12-13 16:12:38 字数 198 浏览 2 评论 0原文

似乎我的笔尖文件包含在我的测试目标中,但它们不存在于主包中,因此当我从主包中按其名称加载笔尖时,我的应用程序崩溃了。我要么需要找到包含我的 nib 文件的正确包,要么需要使用路径加载 nib。

有人有解决方案吗? [NSBundle bundleForClass:[self class]] 不起作用。我认为 nib 和类文件不在同一个包中

It seems as though my nib files are included in my test target, they don't exist in the main bundle, so my app crashes on me when I am loding a nib by its name from the main bundle. I either need to find the correct bundle that includes my nib file, or I need to load a nib using a path.

Does anyone have a solution for either one? [NSBundle bundleForClass:[self class]] doesn't work. I think the nib and class files are not in the same bundle

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2024-12-20 16:12:38

枚举捆绑包可能会有所帮助

for (NSBundle *bundle in [NSBundle allBundles])
{
    // can look for resources in bundle
    locatedPath = [bundle pathForResource:resourcePath ofType:type];

    // or maybe trying and load the nib from it?
    UINib *nib = [UINib nibWithName:@"Blah" bundle:bundle];

    // check for !nil ...
}

It might help to enumerate the bundles

for (NSBundle *bundle in [NSBundle allBundles])
{
    // can look for resources in bundle
    locatedPath = [bundle pathForResource:resourcePath ofType:type];

    // or maybe trying and load the nib from it?
    UINib *nib = [UINib nibWithName:@"Blah" bundle:bundle];

    // check for !nil ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文