Xcode 4 - 标签栏应用程序 - 执行第三个标签时出现问题 [英] Xcode 4 - Tab Bar application - Problem in executing third tab

查看:93
本文介绍了Xcode 4 - 标签栏应用程序 - 执行第三个标签时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Xcode 4,我使用Tab Bar模板创建了一个应用程序(而不是基于View的应用程序)。每个选项卡中都有一个 UISwitch ,当我更改它时, UILabel ON OFF 之间切换。非常简单的应用程序,没有混乱。默认情况下,Xcode 4为我创建了两个选项卡。我还需要第三个选项卡,所以我从对象库中拖动 TabBarItem 并将其放在现有的 TabBarController上。我创建了一个新文件, UIViewController的子类,以下代码分为三个标签。

I have Xcode 4 and I created an application using the Tab Bar template (and not View based app). There is a UISwitch in each of these tabs and when I change it, a UILabel switches between ON and OFF. Very simple app and no confusion. Xcode 4 creates two tabs for me by default. I need a third tab as well, so I drag TabBarItem from the Objects Library and drop it on the existing TabBarController. I create a new file, subclass of UIViewController and the following code goes into three tabs.

以下是界面

#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
    UISwitch *switch1;
    UILabel *status1;
}

@property (nonatomic,retain) IBOutlet UISwitch *switch1;
@property (nonatomic,retain) IBOutlet UILabel *status1;
- (IBAction) switch1Change;
@end

以下是实施

#import "FirstViewController.h"
@implementation FirstViewController
@synthesize switch1;
@synthesize status1;
- (IBAction) switch1Change
{
    if (switch1.on) 
        status1.text = @"ON";
    else
        status1.text = @"OFF";
}

对于SecondViewController和ThirdViewController重复相同的代码,其中ivars更改为switch2,status2和交换机3,STATUS3。该项目的链接是此处

The same code repeats for SecondViewController and ThirdViewController with ivars changing to switch2,status2 and switch3,status3. The link to the project is here

当我在模拟器上运行它时,一切都适用于第一个和第二个选项卡。当我打开第三个选项卡时,出现以下错误因未捕获的异常而终止应用程序'NSUnknownKeyException',原因:[setValue:forUndefinedKey:]:此类不是键值开关3的键值编码投诉。

When I run it on the simulator, everything works fine for the first and second tab. When I open the third tab, I get the following error "Terminating app due to uncaught exception 'NSUnknownKeyException', reason: [ setValue: forUndefinedKey:]: this class is not key value coding-complaint for the key switch3."

当我从 ThirdView.xib 中删除UISwitch时,我没有收到此错误。只有当我添加开关控件时,才会出现此错误。有人可以解释一下发生了什么吗?

When I remove the UISwitch from the ThirdView.xib, I don't get this error. Only when I add the switch control, I get this error. Can somebody please explain what is happening?

推荐答案

在Interface Builder中,您的第三个视图控制器是类 UIViewController (并且没有status3或switch3的出口)。将其类更改为 ThirdViewController ,连接出口,它应该可以工作。

In Interface Builder, your third view controller is of class UIViewController (and doesn't have outlets for status3 or switch3). Change its class to ThirdViewController, wire up the outlets, and it should work.

这篇关于Xcode 4 - 标签栏应用程序 - 执行第三个标签时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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