错误:此类不是关键项目ToolBar的关键字编码兼容代码?

嘿,我不知道我得到一个错误。 我有我的应用程序工作,然后我不知道我做了什么,但现在不会打开,而是我得到这个错误:

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

任何想法可能是什么问题? 我可以添加我的项目代码,如果我需要…

编辑:

所以我看着,在界面生成器/故事板中有一个projectToolBar的链接,在头文件中没有相应的行。 我删除了在IB的问题,但是,现在我得到一个新的错误,它仍然无法正常工作。

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

这是我的taskviewController类:

 #import <UIKit/UIKit.h> #import "AppDelegate.h" #import "newTaskWindow.h" @interface TaskViewController : UIViewController <DismissPopoverDelegate>{ IBOutlet UIScrollView *taskScrollView; AppDelegate * _appDelegate; UIDeviceOrientation orientation; IBOutlet UIView *newTaskView; IBOutlet UIBarButtonItem *newTaskButton; IBOutlet UIBarButtonItem *newTeamMemberButton; IBOutlet UIBarButtonItem *newProjectButton; IBOutlet UIView*taskView; IBOutlet UIToolbar *taskToolBar; NSMutableArray *teamMembers; NSMutableArray *projects; NSMutableArray *tasks; //UIPopoverController *taskPop; int countForX; int countForY; int xOffSet; int yOffset; int xMult; int yMult; int viewContentSize; int countForTaskView; int maxCountForX; int maxCountForY; int incrementForYOffset; int viewContentSizeBase; } - (IBAction)newTask:(id)sender; - (IBAction)newTeamMember:(id)sender; - (IBAction)newProject:(id)sender; -(void)setTasksInScreen; @property(nonatomic, retain) AppDelegate * appDelegate; @property (nonatomic, retain) UIPopoverController *myPopover; @end @protocol NewsVcDelegate <NSObject> - (void)FirstViewController:(TaskViewController*)controller didSelectObject:(id)object; @end 

// FirstViewController.m

 #import "TaskViewController.h" #import "newTaskWindow.h" #import "TeamMember.h" #import "Project.h" #import "newTeamMemberWindow.h" #import "newProjectWindow.h" @implementation TaskViewController @synthesize myPopover; @synthesize appDelegate; - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { NSLog(@"Made it to TaskViewController"); self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil]; [self setTasksInScreen]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } //create new Team member in popover myPopover -(IBAction)newTeamMember:(id)sender{ if ([self.myPopover isPopoverVisible]) { //using the setters and getters "goes thru the proper channels" when accessing objects [self.myPopover dismissPopoverAnimated:YES]; } else { newTeamMemberWindow *teamMemberWindow = [[newTeamMemberWindow alloc]init]; [teamMemberWindow setDelegate:self]; UIPopoverController *teamMemberPop = [[UIPopoverController alloc]initWithContentViewController:teamMemberWindow]; [teamMemberPop setDelegate:self]; [teamMemberPop setPopoverContentSize:CGSizeMake(300, 450)]; //NSLog(@"Got to 6"); self.myPopover = teamMemberPop; [self.myPopover presentPopoverFromBarButtonItem:newTeamMemberButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } } //Create new Project in popover myPopover -(IBAction)newProject:(id)sender{ if ([self.myPopover isPopoverVisible]) { //using the setters and getters "goes thru the proper channels" when accessing objects [self.myPopover dismissPopoverAnimated:YES]; } else { newProjectWindow *projectWindow = [[newProjectWindow alloc]init]; [projectWindow setDelegate:self]; UIPopoverController *projectPop = [[UIPopoverController alloc]initWithContentViewController:projectWindow]; [projectPop setDelegate:self]; [projectPop setPopoverContentSize:CGSizeMake(300, 450)]; self.myPopover = projectPop; [self.myPopover presentPopoverFromBarButtonItem:newProjectButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } } //Create new Task in popover myPopover -(IBAction)newTask:(id)sender{ if ([self.myPopover isPopoverVisible]) { [self.myPopover dismissPopoverAnimated:YES]; } else { NSString* test1 = [[NSString alloc]initWithFormat:@"Robby"]; [teamMembers addObject:test1]; newTaskWindow *newTaskWin = [[newTaskWindow alloc]init]; [newTaskWin setDelegate:self]; UIView *test = [[UIView alloc]init]; [newTaskWin setTeamMembers:teamMembers]; test = newTaskWin.view; UIPopoverController *taskPop = [[UIPopoverController alloc]initWithContentViewController:newTaskWin]; [taskPop setDelegate:self]; [taskPop setPopoverContentSize:CGSizeMake(300, 450)]; self.myPopover = taskPop; [self.myPopover presentPopoverFromBarButtonItem:newTaskButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } } -(void)setTasksInScreen{ //remove all views that were in The task view. If you don't do this, a new view is placed on top everytime you call setTasksInScreen method and the buttons begin to overlap. for (UIView *view in [taskView subviews]) { [view removeFromSuperview]; } //The placement of the buttons is different depending on which orientation we are in. We handle this with an if statement if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){ countForX = 0; countForY = 0; xOffSet = 27; yOffset = 60; maxCountForX = 3; maxCountForY = 4; incrementForYOffset = 911; xMult = 250; yMult = 210; viewContentSize = 0; countForTaskView = 1; viewContentSizeBase = 911; NSLog(@"Portrait view"); } else{ countForX = 0; countForY = 0; maxCountForX = 4; maxCountForY = 3; incrementForYOffset = 654; xOffSet = 41; yOffset = 50; xMult = 240; yMult = 200; viewContentSize = 0; countForTaskView = 1; viewContentSizeBase = 654; NSLog(@"LandScape view"); } //Create Scrollview to be able to scroll through the different tasks taskScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height -45)]; tasks = [[NSMutableArray alloc] initWithArray:self.appDelegate.tasks]; Task *tempTask = [[Task alloc]init]; for(int i =0; i < [tasks count]; i++){ tempTask = [tasks objectAtIndex:i]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; //Set the style that you want the date to be here (ie. MM-DD-YYYY ect) [formatter setDateStyle:NSDateFormatterFullStyle]; NSDate *endDateForButton = [tempTask endDate]; //Use custom Button so that you can add in background pic UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(xOffSet+(countForX*xMult), yOffset +(countForY*yMult), 215, 156); UIImage *buttonBackground = [UIImage imageNamed:@"rectangleImage.png"]; [button setBackgroundImage:buttonBackground forState:UIControlStateNormal]; //add labels to button for information UILabel *taskName = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 200, 45)]; taskName.text = [tempTask taskName]; [taskName setTextAlignment:UITextAlignmentCenter]; [button addSubview:taskName]; //Label that says "Due on" UILabel *dueLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, 200, 45)]; dueLabel.text = @"Due on"; [dueLabel setTextAlignment:UITextAlignmentCenter]; [button addSubview:dueLabel]; UILabel *endDate = [[UILabel alloc]initWithFrame:CGRectMake(5, 80, 200, 45)]; endDate.text = [formatter stringFromDate:[tempTask endDate]]; [endDate setTextAlignment:UITextAlignmentCenter]; [button addSubview:endDate]; countForX++; if(countForX >= maxCountForX) { countForY++; countForX = 0; } if(countForY >=maxCountForY) { countForY = 0; countForX = 0; yOffset +=incrementForYOffset; countForTaskView++; } [taskScrollView addSubview:button]; }//for loop [taskView addSubview:taskScrollView]; [taskView bringSubviewToFront:taskToolBar]; //[taskScrollView addSubview:viewForTaskScrollView]; viewContentSize = viewContentSizeBase * (countForTaskView); taskScrollView.contentSize = CGSizeMake(taskView.frame.size.width, viewContentSize); [taskScrollView setPagingEnabled:YES]; } -(void)setProjectsInScreen{ //remove all views that were in The task view. If you don't do this, a new view is placed on top everytime you call setTasksInScreen method and the buttons begin to overlap. for (UIView *view in [taskView subviews]) { [view removeFromSuperview]; } //The placement of the buttons is different depending on which orientation we are in. We handle this with an if statement if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){ countForX = 0; countForY = 0; xOffSet = 27; yOffset = 60; maxCountForX = 3; maxCountForY = 4; incrementForYOffset = 911; xMult = 250; yMult = 210; viewContentSize = 0; countForTaskView = 1; viewContentSizeBase = 911; NSLog(@"Portrait view"); } else{ countForX = 0; countForY = 0; maxCountForX = 4; maxCountForY = 3; incrementForYOffset = 654; xOffSet = 41; yOffset = 50; xMult = 240; yMult = 200; viewContentSize = 0; countForTaskView = 1; viewContentSizeBase = 654; NSLog(@"LandScape view"); } //Create Scrollview to be able to scroll through the different tasks taskScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height -45)]; projects = [[NSMutableArray alloc] initWithArray:self.appDelegate.projects]; Project *tempProject = [[Project alloc]init]; for(int i =0; i < [tasks count]; i++){ tempProject = [tasks objectAtIndex:i]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(xOffSet+(countForX*xMult), yOffset +(countForY*yMult), 215, 156); UIImage *buttonBackground = [UIImage imageNamed:@"rectangleImage.png"]; [button setBackgroundImage:buttonBackground forState:UIControlStateNormal]; //add labels to button for information UILabel *projectName = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 200, 45)]; projectName.text = [tempProject projectName]; [projectName setTextAlignment:UITextAlignmentCenter]; [button addSubview:projectName]; //Label that says "Due on" UILabel *dueLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, 200, 45)]; dueLabel.text = @"Due on"; [dueLabel setTextAlignment:UITextAlignmentCenter]; [button addSubview:dueLabel]; countForX++; if(countForX >= maxCountForX) { countForY++; countForX = 0; } if(countForY >=maxCountForY) { countForY = 0; countForX = 0; yOffset +=incrementForYOffset; countForTaskView++; } [taskScrollView addSubview:button]; }//for loop [taskView addSubview:taskScrollView]; [taskView bringSubviewToFront:taskToolBar]; //[taskScrollView addSubview:viewForTaskScrollView]; viewContentSize = viewContentSizeBase * (countForTaskView); taskScrollView.contentSize = CGSizeMake(taskView.frame.size.width, viewContentSize); [taskScrollView setPagingEnabled:YES]; } -(void)setTeamMembersInScreen{ //remove all views that were in The task view. If you don't do this, a new view is placed on top everytime you call setTasksInScreen method and the buttons begin to overlap. for (UIView *view in [taskView subviews]) { [view removeFromSuperview]; } //The placement of the buttons is different depending on which orientation we are in. We handle this with an if statement if((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){ countForX = 0; countForY = 0; xOffSet = 27; yOffset = 60; maxCountForX = 3; maxCountForY = 4; incrementForYOffset = 911; xMult = 250; yMult = 210; viewContentSize = 0; countForTaskView = 1; viewContentSizeBase = 911; NSLog(@"Portrait view"); } else{ countForX = 0; countForY = 0; maxCountForX = 4; maxCountForY = 3; incrementForYOffset = 654; xOffSet = 41; yOffset = 50; xMult = 240; yMult = 200; viewContentSize = 0; countForTaskView = 1; viewContentSizeBase = 654; NSLog(@"LandScape view"); } //Create Scrollview to be able to scroll through the different tasks taskScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height -45)]; tasks = [[NSMutableArray alloc] initWithArray:self.appDelegate.tasks]; Task *tempTask = [[Task alloc]init]; for(int i =0; i < [tasks count]; i++){ tempTask = [tasks objectAtIndex:i]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; //Set the style that you want the date to be here (ie. MM-DD-YYYY ect) [formatter setDateStyle:NSDateFormatterFullStyle]; NSDate *endDateForButton = [tempTask endDate]; //Use custom Button so that you can add in background pic UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(xOffSet+(countForX*xMult), yOffset +(countForY*yMult), 215, 156); UIImage *buttonBackground = [UIImage imageNamed:@"rectangleImage.png"]; [button setBackgroundImage:buttonBackground forState:UIControlStateNormal]; //add labels to button for information UILabel *taskName = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 200, 45)]; taskName.text = [tempTask taskName]; [taskName setTextAlignment:UITextAlignmentCenter]; [button addSubview:taskName]; //Label that says "Due on" UILabel *dueLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 50, 200, 45)]; dueLabel.text = @"Due on"; [dueLabel setTextAlignment:UITextAlignmentCenter]; [button addSubview:dueLabel]; UILabel *endDate = [[UILabel alloc]initWithFrame:CGRectMake(5, 80, 200, 45)]; endDate.text = [formatter stringFromDate:[tempTask endDate]]; [endDate setTextAlignment:UITextAlignmentCenter]; [button addSubview:endDate]; countForX++; if(countForX >= maxCountForX) { countForY++; countForX = 0; } if(countForY >=maxCountForY) { countForY = 0; countForX = 0; yOffset +=incrementForYOffset; countForTaskView++; } [taskScrollView addSubview:button]; }//for loop [taskView addSubview:taskScrollView]; [taskView bringSubviewToFront:taskToolBar]; //[taskScrollView addSubview:viewForTaskScrollView]; viewContentSize = viewContentSizeBase * (countForTaskView); taskScrollView.contentSize = CGSizeMake(taskView.frame.size.width, viewContentSize); [taskScrollView setPagingEnabled:YES]; } - (void) dismissPopover:(NSString *)data { /* Dismiss you popover here and process data */ [self.myPopover dismissPopoverAnimated:YES]; [self setTasksInScreen]; //[myPopover dismissPopoverAnimated:YES]; } // Some method, when you create popover -(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{ return YES; } -(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{ } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } - (void)deviceOrientationDidChange:(NSNotification *)notification { [self setTasksInScreen]; } 

@结束

最有可能的是你有一个xib文件,其中包含一个仍然连接到一个名为projectToolBar (现在不存在)的sockets的projectToolBar

您删除了IBOutlet UIToolBar *projectToolBar; 从你的TaskViewController.h文件。


你应该考虑使用源代码控制pipe理,所以你可以看到你做了什么。 😉
Xcode 4指南 – pipe理项目的版本

我打赌你正在尝试使用setValuesForKeysWithDictionary:来填充你的TaskViewController setValuesForKeysWithDictionary:或者类似的东西,而projectToolBar在视图控制器的头文件中不是一个有效的projectToolBar

也可能是@MatthiasBauch说的。

添加几个对象到故事板上的UITableViewCell后,我有同样的错误。 在此之前,该应用程序是完美的工作。

我能够通过去Xcode>首选项>位置>派生数据,解决这个问题,打开目录,并删除与应用程序的名称的文件夹。

希望我的评论会对稍后来这里的人有所帮助。