问题描述
嘿,我无法弄清楚我遇到的错误.我的应用程序正常运行,但我不确定自己做了什么,但是现在无法打开,而是出现此错误:
Hey I can't figure out an error I got. I had my App working and then I'm not sure what I did but it won't open now and instead I get this error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TaskViewController 0x16c9b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key projectToolBar.'
任何想法可能是什么问题?如果需要,我可以添加我的项目代码.
Any Ideas what might be the problem? I can add my project code if I need to...
所以我看了一下,在界面生成器/故事板中,有一个指向projectToolBar的链接,该链接在头文件中没有对应的行.我删除了IB中的问题,但是,现在我遇到了一个新错误,但仍然无法正常工作.
So i looked and in the interface builder/storyboard there was a link to projectToolBar that didn't have a corresponding line in the header file. I deleted the problem in IB, however, now I am getting a new error and it still isn't working.
*** 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类:
Here is my taskviewController class:
#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
// 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.
// e.g. 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];
}
@end
推荐答案
最有可能您拥有一个xib文件,其中包含一个仍连接到名为projectToolBar
的(现在不存在)插座的toolBar.
Most likely you have a xib file that houses a toolBar that is still connected to a (now nonexistent) outlet named projectToolBar
.
您从TaskViewController.h
文件中删除了IBOutlet UIToolBar *projectToolBar;
.
您应该考虑使用源代码管理管理,以便可以看到所做的事情. ;-)
Xcode 4指南-管理项目的版本
You should think about using source control management, so you can see what you did. ;-)
Xcode 4 Guide - Managing Versions of Your Project
这篇关于错误:此类与键projectToolBar的键值编码不兼容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!