Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNavid Mirzaie Milani
6,274 Pointsthis class is not key value coding-compliant for the key error
Hi there everyone,
i've a really strange issue i want to pass my data from my tableviewcontroller to my detailview but i get the error:
uncaught exception 'NSUnknownKeyException', reason: '[<DetailViewController 0x8d7c540> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key teamName.'
here is the code:
Clubs.h
@property(nonatomic,strong) NSString *teamName;
@property(nonatomic,strong) NSString *thumbnail;
-(instancetype)initClubWithName:(NSString *)name;
-(NSURL *)thumbnailUrl;
Clubs.m
-(instancetype)initClubWithName:(NSString *)name{
self = [super init];
if(self){
self.teamName = name;
self.thumbnail = nil;
}
return self;
}
- (NSURL *)thumbnailUrl {
return [NSURL URLWithString:self.thumbnail];
}
ClubsTableViewController.h
#import <UIKit/UIKit.h>
#import "Club.h"
#import "Data.h"
@interface ClubsTableViewController : UITableViewController
@property(nonatomic,strong) Data *holderData;
@property(nonatomic,strong) NSMutableArray *clubs;
@end
ClubsTableViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.holderData = [[Data alloc]init];
self.clubs = [[NSMutableArray alloc] init];
[self.holderData loadDataWithCompletionBlock:^(NSDictionary *objects) {
NSArray *teams = [objects objectForKey:@"clubs"];
for (NSDictionary *c in teams ) {
Club *club = [[Club alloc] initClubWithName:[c objectForKey:@"name"]];
club.thumbnail = [c objectForKey:@"image"];
[self.clubs addObject:club];
}
[self.tableView reloadData];
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"clubsDetail"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Club *clubs = [self.clubs objectAtIndex:indexPath.row];
[segue.destinationViewController setClubName:clubs.teamName];
}
}
DetailViewController.h
@interface DetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *clubLabel;
@property (strong,nonatomic) NSString *clubName;
@end
DetailViewController.m
@synthesize clubLabel,clubName;
- (void)viewDidLoad
{
[super viewDidLoad];
self.clubLabel = [[UILabel alloc] init];
self.clubName = [[NSString alloc] init];
self.clubLabel.text = clubName;
}
everything works fine but when i'm clicking on a table row i get that error. Is there please somebody that can help me out with this.
Navid Mirzaie Milani
6,274 PointsNavid Mirzaie Milani
6,274 PointsNevermind fixed it. If anyone has this issue , they should check their Storyboard if its linked with the wrong IBOutlet.