iOS应用程序(此类不符合密钥数据源的密钥值编码)
我正在制作一个iPhone应用程序,我正在使用这个TableViewController,但是在测试时,我发现了这个错误,我真的不知道该怎么处理它:iOS应用程序(此类不符合密钥数据源的密钥值编码),ios,uitableview,key-value,Ios,Uitableview,Key Value,我正在制作一个iPhone应用程序,我正在使用这个TableViewController,但是在测试时,我发现了这个错误,我真的不知道该怎么处理它: 2012-01-13 13:45:32.947 HandHistory Reviews[3422:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SessionsTableViewController 0x191c
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.'
2012-01-13 13:45:32.947手工历史回顾[3422:707]**
由于未捕获异常“NSUnknownKeyException”而终止应用程序,
原因:'[setValue:forUndefinedKey:]:
此类与密钥数据源的键值编码不兼容。'
有人有主意吗
这是我的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
#导入“SessionsTableViewController.h”
#导入“Session.h”
@接口会话TableViewController()
@属性(非原子,复制)NSArray*会话;
@结束
@实现会话TableViewController
@综合会话=_会话;
#pragma标记-视图生命周期
-(无效)视图将显示:(BOOL)动画
{
[超级视图将显示:动画];
NSMutableArray*会话=[[NSMutableArray alloc]init];
//查找文件
//查找文档目录
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
NSString*path=[path objectAtIndex:0];
NSArray*directoryContent=[[NSFileManager defaultManager]目录目录路径:路径错误:nil];
//循环遍历目录中的每个文件
for(directoryContent中的NSString*文件)
{
NSString*contents=[NSString stringWithContentsOfFile:[[paths objectAtIndex:0]stringByAppendingPathComponent:file]编码:NSUTF8StringEncoding错误:nil];
Session*Session=[[Session alloc]initWithName:file和contents:contents];
[会话添加对象:会话];
}
self.sessions=会话;
}
#pragma标记-表视图数据源
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[self.sessions count];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“会话单元”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
}
//cell.textlab.text=[[self.sessions objectAtIndex:indexath.row]name];
//cell.detailTextLabel.text=[[NSString alloc]initWithFormat:@“%d手”,10];
返回单元;
}
#pragma标记-表视图委托
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
//导航逻辑可能位于此处。创建并推送另一个视图控制器。
/*
*detailViewController=[[alloc]initWithNibName:@“bundle:nil];
// ...
//将选定对象传递给新的视图控制器。
[self.navigationController pushViewController:detailViewController动画:是];
*/
}
@结束
看起来您在interface builder中的连接不正确。在会话TableViewController
中,似乎已将某个内容连接到名为数据源的插座。看起来您可能想反过来做,因为我假设您在SessionsTableViewController
中有一个表视图
因此,您需要将表视图的dataSource
属性附加到SessionsTableViewController
(在您的情况下可能是“文件的所有者”)的实例,而不是相反的方式。检查以确保在标记为Module(就在Class下)的框中没有指定错误的应用程序。这在UI生成器的标识检查器中
通常情况下,您不应该将任何内容指定为模块,因为它默认为标记为“current…”的灰色条目,这意味着它在所有应用程序中都可用。但是,如果您在此处指定了一个应用程序,则该UI项将不可用于项目中的任何其他应用程序,从而在您尝试运行其他应用程序时显示主题错误消息
这就是我的问题…此错误通常发生在插座未正确连接时。在我的情况下,检查outlets连接总是可以解决这个问题。首先检查NSLog会话我知道,我已经将SessionsTableViewController设置为TableView的自定义类,而不是TableViewController,谢谢,这就是我要找的,现在一切都正常了。如果这个评论回答了问题,现在还不清楚如何设置。考虑改写吗?我不知道我还能改写它。如果您在模块中指定了任何内容,则在尝试构建另一个模块时,您将收到指定的操作错误。