2013-07-04 24 views
0

我的問題是,當我構建應用程序它有這個錯誤這個類不是密鑰值符合編碼-的關鍵錯誤

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FirstViewController 0x717ea40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key hourTimeOutOfBraceChanged.' 

這裏是我的頭文件

#import <UIKit/UIKit.h> 
#import "Brace.h" 

@interface FirstViewController : UIViewController 
@property (weak, nonatomic) IBOutlet UILabel *timeOutOfBraceLabel; 
@property (weak, nonatomic) IBOutlet UILabel *weeklyGoalLabel; 
@property (strong, nonatomic) Brace *brace; 

- (IBAction)minuteTimeOutOfBraceChanged:(id)sender; 
//- (IBAction)hourTimeOutOfBraceChanged:(id)sender; 

- (void)updateUI; 
- (void)retreiveData; 
- (void)checkTime; 

@end 

這裏是我的m文件:

#import "FirstViewController.h" 

@interface FirstViewController() 

@end 

@implementation FirstViewController 

- (Brace *)brace { 
if (!_brace) { 
    _brace = [[Brace alloc] init]; 
} 
return _brace; 
} 

- (void)viewDidLoad 
{ 
[self retreiveData]; 
[self updateUI]; 
[super viewDidLoad]; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (void)updateUI { 
// Update timeOutOfBrace 
NSString *timeOutOfBraceString = [[NSString alloc] init]; 
NSString *timeOutOfBraceHoursString = [[NSString alloc] init]; 
NSString *timeOutOfBraceMinutesString = [[NSString alloc] init]; 
NSLog(@"%d", self.brace.timeOutOfBrace.todayHours); 
timeOutOfBraceHoursString = [NSString stringWithFormat:@"%d", self.brace.timeOutOfBrace.todayHours]; 
if (self.brace.timeOutOfBrace.todayMinutes < 10) { 
    timeOutOfBraceMinutesString = [NSString stringWithFormat:@"0%d", self.brace.timeOutOfBrace.todayMinutes]; 
} 
else { 
    timeOutOfBraceMinutesString = [NSString stringWithFormat:@"%d", self.brace.timeOutOfBrace.todayMinutes]; 
} 
timeOutOfBraceString = [NSString stringWithFormat:@"%@:%@", timeOutOfBraceHoursString, timeOutOfBraceMinutesString]; 
self.timeOutOfBraceLabel.text = timeOutOfBraceString; 

// Update weeklyGoal 
NSString *weeklyGoalString = [[NSString alloc] init]; 
NSString *totalHoursThisWeekString = [[NSString alloc] init]; 
int totalHoursThisWeekDecimal = self.brace.timeOutOfBrace.overallHours + round(self.brace.timeOutOfBrace.overallMinutes/60); 
totalHoursThisWeekString = [NSString stringWithFormat:@"%d", totalHoursThisWeekDecimal]; 
weeklyGoalString = [NSString stringWithFormat:@"%d", self.brace.timeOutOfBrace.goalForWeek]; 
self.weeklyGoalLabel.text = [NSString stringWithFormat:@"%@/%@", totalHoursThisWeekString, weeklyGoalString]; 
} 

- (void)retreiveData { 
self.brace.timeOutOfBrace.todayHours = 4; 
self.brace.timeOutOfBrace.todayMinutes = 0; 
self.brace.timeOutOfBrace.overallHours = 12; 
self.brace.timeOutOfBrace.overallMinutes = 0; 
self.brace.timeOutOfBrace.goalForWeek = 28; 
} 

- (IBAction)minuteTimeOutOfBraceChanged:(id)sender { 
if ([[sender currentTitle] isEqualToString:@"+"]) { 
    self.brace.timeOutOfBrace.todayMinutes = [self.brace timeOutOfBraceChanged:YES 
                       :@"minutes" 
                       :self.brace.timeOutOfBrace.todayMinutes]; 
} 
else { 
    self.brace.timeOutOfBrace.todayMinutes = [self.brace timeOutOfBraceChanged:NO 
                       :@"minutes" 
                       :self.brace.timeOutOfBrace.todayMinutes]; 
} 
[self checkTime]; 
} 

- (IBAction)hourTimeOutOfBraceChanged:(id)sender { 
if ([[sender currentTitle] isEqualToString:@"+"]) { 
    self.brace.timeOutOfBrace.todayMinutes = [self.brace timeOutOfBraceChanged:YES 
                       :@"hours" 
                       :self.brace.timeOutOfBrace.todayHours]; 
} 
else { 
    self.brace.timeOutOfBrace.todayMinutes = [self.brace timeOutOfBraceChanged:NO 
                       :@"hours" 
                       :self.brace.timeOutOfBrace.todayHours]; 
} 
[self checkTime]; 
} 

- (void)checkTime { 
if (self.brace.timeOutOfBrace.todayMinutes < 0) { 
    self.brace.timeOutOfBrace.todayMinutes = 45; 
    self.brace.timeOutOfBrace.todayHours -= 1; 
    } 
    if (self.brace.timeOutOfBrace.todayMinutes > 45) { 
     self.brace.timeOutOfBrace.todayMinutes = 0; 
     self.brace.timeOutOfBrace.todayHours += 1; 
    } 
} 

@end 

我誠實地嘗試了我所知道的所有可能的解決方案。我檢查了所有連接,以我的觀點,他們很好。先謝謝你。

+1

爲什麼是'// - (IBAction爲)hourTimeOutOfBraceChanged:(ID )發件人;'註釋掉?您的操作方法具有選擇器「hourTimeOutOfBraceChanged:」(尾隨冒號),但錯誤消息抱怨「hourTimeOutOfBraceChanged」(不帶冒號),因此其中一個連接與方法選擇器完全不匹配。 –

+0

嘗試刪除派生數據? –

+0

哦,對不起,我不是故意有這個評論了它沒有當我得到的錯誤我只是想用不同的方法來解決問題 – jamespick

回答

1

如果您在界面構建器中爲該缺失關鍵字的某個UILabel實例提供了密鑰,然後將其刪除,則會導致該錯誤。按住Ctrl點擊視圖控制器的文件所有者,然後從中刪除缺少的密鑰。

+0

謝謝你這個工作我有東西鏈接到一個不存在的對象。 – jamespick

0

看起來你正在用nib文件創建一個FirstViewController對象。 你可能做這樣的事情:

[[[FirstViewController alloc] initWithNibName:@"AnOtherXibFile" bundle:nil] autorelease]; 

這意味着它會創建FirstViewController對象喜歡視圖編譯進AnOtherXibFile.xib文件。

你可以仔細檢查你創建FirstViewController與它正確的xib文件?
你應該是這樣的:

[[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 

或者,如果你使用了正確的廈門國際銀行,仔細檢查所有的關於你的ViewController ...

相關問題