2012-01-13 16 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

相關問題