我有一个UIViewController,其中包含一个UITableView。由于视图上还有其他东西,所以该UIViewController不是UITableViewController。如果我不连接任何outlet,则空表格将显示在视图上,同时还有其他内容,没有错误。如果我将UIViewController的outlet与UITableView连接起来,则会出现以下错误:
'[<UIViewController 0x748a420> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableStories.'
如果我还将UITableView的datasource和delegate outlet也连接到这个UIViewController中,则会得到相同的错误。这是该视图控制器的.h文件:
'[<UIViewController 0x748a420> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableStories.'
如果我还将UITableView的datasource和delegate outlet也连接到这个UIViewController中,则会得到相同的错误。这是该视图控制器的.h文件:
#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;
这里是 .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;
}
可能与我的Core Data命令有关,但我已经尝试了堆栈中提到的其他解决方案来解决这个错误,但目前为止还没有任何作用。 :-/
另外,我从另一个应用程序导入了故事板,所以可能会引起一些麻烦。