通过静态库从自定义捆绑包加载 XIB
我想通过静态库中的一些代码从 CFBundle 加载 XIB。
示例:
MyViewController * foo = [[Static Library] instance] getMyViewController];
所以我在 CFBundle 中手动创建了一个 MyViewController .xib,位于其资源目录中。
但是,如果我尝试通过 getMyViewController 中的 [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:MyBundlePointer] 加载它,我会得到 NSInternalInconsistencyException。
有什么想法吗?我或多或少对这一点感到困惑。不确定是否可以做到这一点。
I want to load a XIB from a CFBundle, via some code in a Static Library.
Example:
MyViewController * foo = [[Static Library] instance] getMyViewController];
So I have a MyViewController .xib in a CFBundle I manually create, in it's Resources dir.
But if I try to load it via [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:MyBundlePointer] in getMyViewController I get NSInternalInconsistencyException.
Any idea? I am more or less stumped on this one. Not sure it is even possible to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我目前在 Monotouch 上遇到了完全相同的问题,这就是我发现你的问题的原因。
我得到了和你一样的例外。这让我假设我面临的不是 Monotouch 问题,而是 XIB/Cocotouch 的基本(错误)行为。
所以答案是:不,不可能。虽然很伤心。
勒内
I'm currently having exactly the same issue with Monotouch and that's why I found your question.
I get the very same exception as you do. This makes me assume that I'm not facing a Monotouch issue but a basic (mis)behavior of XIBs/Cocoatouch.
So the answer is: no, it is not possible. Very sad though.
René
这可能不是您的具体问题,但它是一个潜在的问题:
CFBundle 不是与 NSBundle 的免费桥接。由于您在描述中使用了术语 CFBundle,我想知道您是否传递的是 CFBundle,而不是 NSBundle。
这是两种不同的类型,您需要显式创建一个 NSBundle 实例,因为您不能像使用 CF/NS-String、Array、Data 等那样将 CFBundleRef 转换为 NSBundle。
this may not be your specific issue, but it is potentially an issue:
CFBundle is not toll-free-bridged with NSBundle. since you used the term CFBundle in your description, i am wondering if you're passing a CFBundle, rather than an NSBundle.
these are two distinct types and you'll need to explicitly create an NSBundle instance because you can't just cast a CFBundleRef as a NSBundle as you can with CF/NS-String, Array, Data, etc.