2013-07-04 23 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 ...

相关问题