3

I have a UIViewController with a UITableView inside of it. The UIViewController is not a UITableViewController, since there are other things on the view. If I don't hook up any outlets, the empty table appears on the view along with other things, with no error. If I hook up the outlet from the UIViewController to the UITableView I get the following error:

'[<UIViewController 0x748a420> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableStories.'

If I also hook up the datasource and delegate outlets from UITableView to the UIViewController, I get the same error. Here is the .h for the view controller

#import <UIKit/UIKit.h>

@interface IntroViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>


@property (nonatomic, weak) IBOutlet UITableView *tableStories;
@property (nonatomic, strong) NSManagedObjectContext* managedObjectContext;
@property (nonatomic, strong) NSArray *stories;

And here is the .m

@implementation IntroViewController

@synthesize tableStories;
@synthesize stories;
@synthesize managedObjectContext;


- (void)viewDidLoad
{
    [super viewDidLoad];

    tableStories.delegate = self;
    tableStories.dataSource = self;

    managedObjectContext = ((ReadMeAppDelegate *)[UIApplication sharedApplication].delegate).managedObjectContext;
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"RMStory" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];
    NSError *error;
    self.stories = [managedObjectContext executeFetchRequest:fetchRequest error:&error];

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [stories count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    RMStory *thisStory = [stories objectAtIndex:indexPath.row];
    cell.textLabel.text = thisStory.title;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", thisStory.author];

    return cell;
}

It might have something to do with my Core Data commands, but I've been trying out the other solutions mentioned on the stack to get past this error, and so far nothing works. :-/

Also, I imported the storyboard from another App, so maybe that might be causing some trouble.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
syzygy
  • 1,356
  • 3
  • 16
  • 28
  • Just to be clear, I have not hooked up any other outlets or anything else to the outlets mentioned. – syzygy Oct 12 '12 at 00:12
  • possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"](http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key) – jtbandes Aug 16 '15 at 18:26

2 Answers2

2

I figured it out. I was getting an error at the very beginning of the debugger output that said

Unknown class IntroViewController in Interface Builder file.

I looked up the error on StackExchange and found the answer here It was Matthew that gave the answer I used. I had to add IntroViewController to the list of compile sources. I'm not sure what that means, or why it didn't prevent the program from running in the absence of the table view, but now it works. Thanks StackExchange!!

Community
  • 1
  • 1
syzygy
  • 1,356
  • 3
  • 16
  • 28
  • This can also happen if you don't have @implementation declared. I discuss it further at http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime/12755891#12755891 and http://stackoverflow.com/questions/12790902/uicollectionview-doesnt-contain-uicollectionviewcell-in-ib/22797318#22797318 – Zack Morris Apr 01 '14 at 21:42
1

In IB, don't forget to set your UIViewController class to IntroViewController.

John Estropia
  • 17,460
  • 4
  • 46
  • 50
  • I double checked it, changed it away and back again and rehooked up all the outlets and I got the same error. Thanks though! – syzygy Oct 12 '12 at 01:50
  • If so, then have you checked that the `init` being used for your view controller is actually the one that loads the nib file? – John Estropia Oct 12 '12 at 02:17