ios 此类不符合键 authView 的键值编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5109309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
this class is not key value coding-compliant for the key authView
提问by Robert Bed
When i run my app on simulator it runs well, when i try with device doesn't work and i get these errors:
当我在模拟器上运行我的应用程序时它运行良好,当我尝试使用设备时无法正常工作并且出现以下错误:
NOTE: i didn't find any kind of class authView in my code
注意:我在我的代码中没有找到任何类型的 authView
2011-02-24 12:04:14.472 TestP[473:307] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TestP 0x19d2b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key authView.'
*** Call stack at first throw:
(
0 CoreFoundation 0x33ac0987 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3347b49d objc_exception_throw + 24
2 CoreFoundation 0x33ac0705 -[NSException dealloc] + 0
3 Foundation 0x3367db4f -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 182
4 Foundation 0x3367d03b _NSSetUsingKeyValueSetter + 90
5 Foundation 0x3367eda3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 194
6 Foundation 0x33630b17 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 130
7 UIKit 0x3224c60f -[UIRuntimeOutletConnection connect] + 66
8 CoreFoundation 0x33a63fc7 -[NSObject(NSObject) performSelector:] + 18
9 CoreFoundation 0x33a6cd51 -[NSArray makeObjectsPerformSelector:] + 388
10 UIKit 0x3224b577 -[UINib instantiateWithOwner:options:] + 586
11 UIKit 0x3224cb39 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 92
12 UIKit 0x3209e871 -[UIApplication _loadMainNibFile] + 96
13 UIKit 0x3209a1fd -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 180
14 UIKit 0x3206648b -[UIApplication handleEvent:withNewEvent:] + 1114
15 UIKit 0x32065ec9 -[UIApplication sendEvent:] + 44
16 UIKit 0x32065907 _UIApplicationHandleEvent + 5090
17 GraphicsServices 0x33b0ef03 PurpleEventCallback + 666
18 CoreFoundation 0x33a556ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
19 CoreFoundation 0x33a556c3 __CFRunLoopDoSource1 + 166
20 CoreFoundation 0x33a47f7d __CFRunLoopRun + 520
21 CoreFoundation 0x33a47c87 CFRunLoopRunSpecific + 230
22 CoreFoundation 0x33a47b8f CFRunLoopRunInMode + 58
23 UIKit 0x32099309 -[UIApplication _run] + 380
24 UIKit 0x32096e93 UIApplicationMain + 670
25 TestP 0x00002213 main + 98
26 TestP 0x000021ac start + 40
)
terminate called after throwing an instance of 'NSException'
采纳答案by Robert Bed
something went wrong when in xcode 4 with some reference , cause i declared IBOutlet that reference authView then run and it worked!, then i removed the IBOutlet declaration and worked well
在 xcode 4 中使用一些引用时出了点问题,因为我声明了引用 authView 的 IBOutlet 然后运行并且它工作了!,然后我删除了 IBOutlet 声明并且运行良好
回答by Dave DeLong
You've probably got your File's Owner stuff messed up in your xibs. This exception is getting thrown during nib unarchiving (as evidenced by +[UINib...]
in the backtrace). It's attempting to hook up your IBOutlets
that you defined.
你可能已经把你的文件所有者的东西弄乱了你的 xib。在 nib 取消归档期间抛出此异常(如+[UINib...]
回溯所示)。它试图连接IBOutlets
你定义的。
One of your views is set up to be the authView
of the the File's Owner. However, when it's time to unarchive the nib, the owner doesn't have an authView
property, so the unarchiving is failing.
您的一个视图被设置authView
为文件所有者的。但是,当需要取消存档笔尖时,所有者没有authView
财产,因此取消存档失败。
回答by Waqas Raja
@Dave DeLong pointed out right.
@Dave DeLong 指出正确。
Workaround
解决方法
- Find when the exception thrown, which viewController is being loaded.
- Then check the nib file of the viewController, there must be an
IBOutlet
attached in xib but might be missed in the viewController.h file or might be some control which was attached is missing in xib file.
- 查找何时抛出异常,正在加载哪个viewController。
- 然后检查viewController 的nib 文件,xib 中肯定有
IBOutlet
附件,但viewController.h 文件中可能会丢失,或者xib 文件中可能缺少附加的某些控件。
Why running in Simulator?Sometimes it ends in messing up.
为什么在模拟器中运行?有时它以搞砸结束。
Just do the steps
只做步骤
- Build -> Clean
- Build -> Clean All Targets
- 构建 -> 清洁
- 构建 -> 清理所有目标
Now it runs the real code, may be issue got resolve on device also or may be it start throwing exception on simulator also in case if there is really an issue. (I already have mentioned workaround)
现在它运行真正的代码,可能是设备上的问题也得到了解决,或者它也可能开始在模拟器上抛出异常,以防万一真的有问题。(我已经提到了解决方法)
回答by daveomcd
This is how I solved this problem. I went into my 'Story Board' file and selected the view that was causing the problems. I then clicked on the Connections Inspector
tab and you will see connection(s) with exclamation points to the right instead of solid circles. Remove these and make adjustments if necessary. Save>Run your app and should work. Hope this helps :)
这就是我解决这个问题的方法。我进入我的“故事板”文件并选择了导致问题的视图。然后我单击Connections Inspector
选项卡,您将看到右侧带有感叹号而不是实心圆圈的连接。删除这些并在必要时进行调整。保存>运行您的应用程序,应该可以工作。希望这可以帮助 :)
回答by oistanchev
I think that one possible cause for raising that exception is when you have changed the name of some IBOutlet variable after the storyboard connections are already done. Thus the UI element in the storyboard is still referencing to the old variable name. I solved this for me by checking the XML representation of the storyboard (Right click on your .storyboard file and open it as Source Code) and deleting the old (unneeded) IBOutlet variable name.
我认为引发该异常的一个可能原因是在故事板连接完成后更改了某些 IBOutlet 变量的名称。因此故事板中的 UI 元素仍然引用旧的变量名称。我通过检查故事板的 XML 表示(右键单击您的 .storyboard 文件并将其作为源代码打开)并删除旧的(不需要的)IBOutlet 变量名称为我解决了这个问题。
For example let say you have one UITextField on the storyboard and have the corresponding property for it:
例如,假设您在情节提要上有一个 UITextField 并具有相应的属性:
@property (retain, nonatomic) IBOutlet UItextField *myTextField;
You connect the UI element in the storyboard to that property and then you decide to rename somehow the variable. Now if you right click on your UITextField in the storyboard, you will notice that there exists two referencing outlets - the old one and the new one. You can delete the old one by clicking 'x' sign in the Connections Inspector or by editing the XML variant of the storyboard file.
您将故事板中的 UI 元素连接到该属性,然后您决定以某种方式重命名该变量。现在,如果您右键单击情节提要中的 UITextField,您会注意到存在两个引用出口 - 旧的和新的。您可以通过单击 Connections Inspector 中的“x”符号或编辑情节提要文件的 XML 变体来删除旧的。
回答by richy
I just cleaned the project and deleted the app from the device and it worked again. Error was referencing a view that i had already removed.
我刚刚清理了项目并从设备中删除了该应用程序,然后它又可以正常工作了。错误引用了我已经删除的视图。
回答by Vinay W
i have found these errors arise mostly when you connect properties, edit them, and connect them again.. analyse your connection inspector for unexpected values, that remain from your previously created and destroyed connection.
我发现这些错误主要是在您连接属性、编辑它们并再次连接它们时出现的。
回答by Juan Fran Jimenez
In my case it was even more spooky. I had a XIB associated to the VC that I had removed completely as went for code-only. Run on Simulator nicely but would crash on Device systematically.
就我而言,它甚至更令人毛骨悚然。我有一个与 VC 关联的 XIB,我已经完全删除了它,因为它只用于代码。在模拟器上运行良好,但会系统地在设备上崩溃。
So I clean, rebuild, closed XCode, went for a snack and shout at the mac. Nothing, the compiler kept pointing to an inexistent button on an inexistent XIB.
所以我清理,重建,关闭 XCode,去吃点心,对着 mac 大喊大叫。没什么,编译器一直指向不存在的 XIB 上不存在的按钮。
Tried by changing the name of the class and that worked!
通过更改班级名称进行了尝试,并且奏效了!
回答by Jesús Hurtado
It seems that your Interface Builder did not work properly. As suggested before, try by cleaning and rebuild. If it doesn′t work, I′d suggest you to re-create your xib interface. It worked for me in a similar occasion.
您的 Interface Builder 似乎无法正常工作。如前所述,尝试清洁和重建。如果它不起作用,我建议您重新创建您的 xib 界面。它在类似的场合对我有用。
回答by mskw
You have probably created an IBOutlet, then deleted it, then linked a new one, but in the xib 'Inspector' you forgot to delete the link and now have a duplicate IBOutlet ref that the compiler cannot find.
您可能已经创建了一个 IBOutlet,然后删除了它,然后链接了一个新的,但是在 xib 'Inspector' 中,您忘记删除链接,现在有一个编译器找不到的重复 IBOutlet 引用。