简体   繁体   English

从nib文件加载视图

[英]Loading view from a nib file

So I have a view that I have put together in another .xib file. 所以我有一个视图,我把它放在另一个.xib文件中。 It also has it's own .h/.m files. 它还有自己的.h / .m文件。

I am trying to allocate an instance of it in my mainViewController and I keep getting: 我试图在我的mainViewController中分配它的一个实例,我不断得到:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<XXX 0x1c556390> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX

I am using the following code 我使用以下代码

NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"SubviewClass"
                                                  owner:self
                                                options:nil];
self.subview = (SubviewClass *)[nibViews objectAtIndex:0];
self.subview.frame = CGRectMake(82, 182, 155, 96);
[self.view addSubview:self.subview];

However it keeps crashing on the first line. 然而,它一直在崩溃。

Your SubviewClass nib has an object that is hooked up to an outlet that doesn't exist. 您的SubviewClass笔尖有一个连接到不存在的插座的对象。 Check the connections for each object in your nib and check that the owner is correct and has the outlets that you are connecting to. 检查笔尖中每个对象的连接,并检查所有者是否正确并且具有要连接的插座。

In your nib you have a view or control that is mapped to a property which does not exist on the owner of the nib which in your code is whatever object calls 在你的nib中你有一个视图或控件映射到一个属性,该属性在nib的所有者中不存在,在你的代码中是任何对象调用


NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"SubviewClass"
                                                  owner:self
                                                options:nil];

I suspect that you nib file has some problem. 我怀疑你的nib文件有一些问题。 Check all the connections from your controller object... 检查控制器对象的所有连接...

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

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