我有Xcode 4,並且使用選項卡欄模板(而不是基於視圖的應用程序)創建了一個應用程序。有一個UISwitch在每個這些標籤,並且當我改變它,一個的UILabel和OFF之間開關ON。非常簡單的應用程序,沒有混淆。 Xcode 4默認爲我創建了兩個選項卡。我還需要第三個選項卡,因此我從對象庫中拖動TabBarItem,並將其放在現有的TabBarController上。我創建了一個新文件,UIViewController的子類,下面的代碼進入了三個選項卡。Xcode 4 - 選項卡欄應用程序 - 執行第三個選項卡時的問題
下面是接口
#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與實例變量改變連接switch2,STATUS2和交換機3,STATUS3。該項目的鏈接是here
當我在模擬器上運行它,一切工作正常的第一個和第二個選項卡。當我打開第三個選項卡時,出現以下錯誤「由於未捕獲的異常'NSUnknownKeyException'導致應用程序終止,原因:[setValue:forUndefinedKey:]:此類不是鍵開關3的鍵值編碼投訴。
當我從ThirdView.xib刪除UISwitch,我沒有得到這個錯誤。只有當我添加開關控制,我得到這個錯誤。有人可以解釋發生了什麼嗎?
我只能說對我自己是「該死的」,對你先生「哇,謝謝」。你是最好的! – harihb 2011-04-26 07:30:40