2012-01-13 24 views
8

Tôi đang tạo một ứng dụng iPhone và đang làm việc tại TableViewController này, nhưng khi thử nghiệm, tôi gặp phải lỗi này và tôi không t thực sự biết phải làm gì với nó:Ứng dụng iOS (lớp này không tuân thủ mã hóa khóa giá trị cho khóa dữ liệu chính)

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.' 

Có ai có ý tưởng không?

Đây là tập tin SessionTableViewController.m tôi:

#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

séc ra NSLog phiên họp đầu tiên – Hiren

Trả lời

16

Dường như bạn đã có dây mọi thứ lên trong xây dựng giao diện không chính xác. Có vẻ như bạn đã đính kèm thứ gì đó vào ổ cắm được gọi là dataSource trong số SessionsTableViewController của mình. Có vẻ như bạn có thể muốn làm điều đó theo cách khác vì tôi cho rằng bạn có chế độ xem bảng trong SessionsTableViewController.

Vì vậy, bạn cần đính kèm thuộc tính dataSource của chế độ xem bảng vào trường hợp của bạn là SessionsTableViewController (có thể là "Chủ sở hữu tệp" trong trường hợp của bạn), chứ không phải theo cách khác.

+0

tôi thấy, tôi đã thiết SessionsTableViewController tôi như lớp tùy chỉnh cho TableView của tôi thay vì TableViewController của tôi, cảm ơn, đây là những gì tôi đang tìm kiếm , mọi thứ hoạt động ngay bây giờ. –

0

Kiểm tra để đảm bảo bạn chưa chỉ định ứng dụng sai trong hộp có gắn nhãn Mô-đun (ngay dưới Lớp). Điều này nằm trong Thanh tra danh tính trong Trình tạo giao diện người dùng.

Bạn thường không nên chỉ định bất kỳ thứ gì được chỉ định làm Mô-đun, vì nó mặc định là mục nhập có màu xám có nhãn "hiện tại ....", có nghĩa là có sẵn trong tất cả các ứng dụng. Tuy nhiên, nếu bạn đã chỉ định một ứng dụng ở đây, mục giao diện người dùng sẽ không khả dụng cho bất kỳ ứng dụng nào khác trong dự án của bạn, cung cấp cho bạn thông báo lỗi chủ đề khi bạn cố gắng chạy các ứng dụng khác.

Đó là vấn đề của tôi ...

+0

Nếu bình luận này trả lời câu hỏi, nó không ngay lập tức rõ ràng như thế nào. Cân nhắc viết lại? –

+1

Tôi không biết làm cách nào khác để tôi có thể viết lại. Nếu bạn có bất cứ điều gì được chỉ định trong Module, bạn sẽ nhận được lỗi OP được chỉ định khi bạn cố gắng xây dựng một mô-đun khác. –

Các vấn đề liên quan