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

は、チェックアウト、私が見 – Hiren

答えて

16

誤っインターフェイスビルダーで物事を有線ているように見えます。 SessionsTableViewControllerdataSourceというコンセントに何かを付けたようです。 SessionsTableViewControllerにテーブルビューを持っていると仮定すると、あなたはおそらく他の方法でそれをやりたかったようです。

したがって、テーブルビューのdataSourceプロパティは、別の方法ではなく、SessionsTableViewControllerのインスタンス(おそらく "ファイルの所有者")にアタッチする必要があります。

+0

のNSLogセッション最初に、私が代わりに私のTableViewControllerの私のテーブルビューのカスタムクラスとしての私のSessionsTableViewControllerを設定して、おかげで、これは私が探していたものです、すべては今働く。 –

0

「モジュール」というラベルの付いたボックス(「クラス」の下)に間違ったアプリケーションを指定していないことを確認してください。これは、UIビルダのIDインスペクタにあります。

通常、「現在の....」というラベルの付いた灰色の項目がデフォルトで使用されているため、すべてのアプリケーションで利用可能です。しかし、ここでアプリケーションを指定していれば、他のアプリを実行しようとすると主題のエラーメッセージが表示され、プロジェクトの他のアプリでUI項目を利用できなくなります。

私の問題だった

...

+0

このコメントがこの質問に答えると、すぐには分かりません。言い直すことを検討するか? –

+1

他にどのように言い換えることができないのか分かりません。モジュールに何か指定されていれば、別のモジュールをビルドしようとするとOPが指定したエラーが発生します。 –

関連する問題