【问题标题】:Xcode 4 - Tab Bar application - Problem in executing third tabXcode 4 - 选项卡栏应用程序 - 执行第三个选项卡时出现问题
【发布时间】:2011-04-26 06:38:41
【问题描述】:

我有 Xcode 4,我使用 Tab Bar 模板(而不是基于视图的应用程序)创建了一个应用程序。每个选项卡中都有一个 UISwitch,当我更改它时,一个 UILabelONOFF 之间切换.非常简单的应用程序,没有混淆。 Xcode 4 默认为我创建了两个选项卡。我还需要第三个选项卡,因此我将 TabBarItem 从对象库中拖放到现有的 TabBarController 上。 我创建了一个新文件,UIViewController 的子类,下面的代码进入三个选项卡。

以下是界面

#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 和 switch3,status3。该项目的链接是here

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

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

【问题讨论】:

    标签: ipad xcode4 uitabbar ios4


    【解决方案1】:

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

    【讨论】:

    • 我只能对自己说“该死的”,对先生说“哇,谢谢你”。你是最棒的!
    猜你喜欢
    • 1970-01-01
    • 2011-12-18
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多