App crashes when tab bar item is selected

空扰寡人 提交于 2019-12-11 12:57:09

问题


I have a tab bar item with a UIScrollView and all the code works.

I link the UIScrollView IBOutlet in IB to a UIScrollView I placed in my View.

When I run the app and select the tab bar item I get the following error.

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key scrollView.'

I have no idea what this is. When I disconnect the ScrollView IBOutlet, then there is no crash.

Thanks


回答1:


You probably renamed the name of the scrollView in the code without re-connecting the outlet in Interface Builder. Double check your code to make sure the spelling is the same as in Interface Builder, and for good measure, reconnect the outlet to scrollView.

Referring to this Apple forum thread, UITabBarController has multiple UIViewControllers each of which has its own nib file assigned to it. It's up to you to make sure you change the UIViewController's class file: in the nib file for each view controller and in the tab bar controller's nib file, you also have to do the same thing by changing each view controller's nib file and class.

So all in all you have to update settings in two places: the individual nib files for the view controllers and the tab bar controller's nib file. Think of it as creating the connections/bridges between the individual nib files and the tab bar controller.

Once these connections are made, your program should have no problem accessing your scrollView outlet, since that is how it ultimately accesses it: by using key-value coding by means of your tab bar controller (at least, that's my understanding). As of now it can't because the tab bar controller is not connected properly.



来源:https://stackoverflow.com/questions/3481409/app-crashes-when-tab-bar-item-is-selected

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