syzygy
syzygy

Reputation: 1396

iOS not key value coding compliant uitableview

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.

Upvotes: 3

Views: 3894

Answers (2)

syzygy
syzygy

Reputation: 1396

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!!

Upvotes: 2

John Estropia
John Estropia

Reputation: 17500

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

Upvotes: 1

Related Questions