选择选项卡栏项目时,应用程序崩溃 [英] App crashes when tab bar item is selected

查看:48
本文介绍了选择选项卡栏项目时,应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有UIScrollView的选项卡栏项,并且所有代码都有效.

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

我将IB中的UIScrollView IBOutlet链接到放置在视图中的UIScrollView.

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.

由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:此类与键scrollView的键值编码不兼容.'

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

我不知道这是什么.当我断开ScrollView IBOutlet的连接时,没有崩溃.

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

谢谢

推荐答案

您可能在代码中重命名了scrollView的名称,而无需重新连接Interface Builder中的插座.仔细检查您的代码,以确保其拼写与Interface Builder中的相同,并在适当的情况下,将插座重新连接到scrollView.

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.

引用此Apple论坛线程 UITabBarController 有多个 UIViewControllers ,每个都有自己的nib文件分配给它.确保由您决定是否更改 UIViewController 的类文件:在每个视图控制器的nib文件中以及选项卡栏控制器的nib文件中的通过更改每个视图控制器的nib文件和类来做相同的事情.

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.

因此,总而言之,您必须在两个位置更新设置:用于视图控制器的单个nib文件和标签栏控制器的nib文件.可以将其视为在各个笔尖文件和选项卡栏控制器之间创建连接/桥.

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.

一旦建立了这些连接,您的程序就可以毫无问题地访问您的 scrollView 插座,因为这是最终访问它的方式:通过使用标签栏控制器使用键值编码(至少,这是我的理解).到目前为止,由于标签栏控制器未正确连接,因此无法实现.

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.

这篇关于选择选项卡栏项目时,应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆