2012-01-13 75 views
8

我正在制作一个iPhone应用程序,而且我正在使用此TableViewController,但是在测试时,出现此错误,我真的不知道该怎么处理它:iOS应用程序(此类不是关键值编码兼容的关键数据源)

2012-01-13 13:45:32.947 HandHistory Reviews[3422:707] *** 
Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<SessionsTableViewController 0x191cb0> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key dataSource.' 

任何人都有想法吗?

这是我SessionTableViewController.m文件:

#import "SessionsTableViewController.h" 
#import "Session.h" 

@interface SessionsTableViewController() 

@property (nonatomic, copy) NSArray *sessions; 

@end 

@implementation SessionsTableViewController 

@synthesize sessions = _sessions; 

#pragma mark - View lifecycle 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    NSMutableArray *sessions = [[NSMutableArray alloc] init]; 

    // Looking for files 
    // Finding the Documents directory 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *path = [paths objectAtIndex:0]; 
    NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; 

    // Looping through each file in the directory 
    for (NSString *file in directoryContent) 
    { 
     NSString *contents = [NSString stringWithContentsOfFile:[[paths objectAtIndex:0] stringByAppendingPathComponent:file] encoding:NSUTF8StringEncoding error:nil]; 

     Session *session = [[Session alloc] initWithName:file andContents:contents]; 

     [sessions addObject:session]; 
    } 

    self.sessions = sessions; 
} 

#pragma mark - Table view data source 

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

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    //cell.textLabel.text = [[self.sessions objectAtIndex:indexPath.row] name]; 
    //cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%d hands", 10]; 

    return cell; 
} 



#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Navigation logic may go here. Create and push another view controller. 
    /* 
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 
    // ... 
    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    */ 
} 

@end 
+0

退房的NSLog会议第一 – Hiren 2012-01-13 12:02:35

回答

16

它看起来就像你在Interface Builder有线东西不正确。看起来你已经在你的SessionsTableViewController中附加了一个叫做dataSource的插座。看起来你可能想这样做,因为我假设你在SessionsTableViewController有一个表格视图。

所以,你需要将你的表视图的dataSource属性附加到你的实例SessionsTableViewController(在你的案例中可能是“文件的所有者”),而不是相反的方式。

+0

我明白了,我已经把我的SessionsTableViewController作为我的TableView,而不是我的TableViewController,感谢自定义类,这就是我一直在寻找,现在一切正常。 – 2012-01-13 12:08:29

0

检查以确保您没有在标为Module(仅在Class下)框中指定错误的应用程序。这在UI Builder中的Identity Inspector中。

您通常不应该指定为Module,因为它默认为灰色的标签为“current ....”,这意味着它在所有应用程序中都可用。但是,如果您在此处指定了应用程序,则UI项目将无法用于项目中的任何其他应用程序,当您尝试运行其他应用程序时,会向您提供主题错误消息。

这是我的问题...

+0

如果这个评论回答了这个问题,那么目前还不清楚如何。考虑重新措词? – 2016-07-20 03:55:36

+1

我不知道我可以如何改写它。如果您在Module中指定了任何内容,则会在尝试构建另一个模块时收到OP指定的错误。 – 2016-09-24 00:24:49

相关问题