2012-01-13 11 views
8

मैं एक आईफोन ऐप बना रहा हूं, और मैं इस टेबल व्यू कंट्रोलर पर काम कर रहा हूं, लेकिन परीक्षण करते समय, मुझे यह त्रुटि मिलती है, और मैं ' टी वास्तव में पता है कि इसके साथ क्या करना है:आईओएस ऐप (यह क्लास कुंजी डेटा स्रोत के लिए महत्वपूर्ण मूल्य कोडिंग-अनुरूप नहीं है)

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

उत्तर

16

ऐसा लगता है कि गलत तरीके से इंटरफ़ेस बिल्डर में बातें तार कर दिया है। ऐसा प्रतीत होता है कि आपने अपने SessionsTableViewController में dataSource नामक आउटलेट से कुछ जुड़ा हुआ है। ऐसा लगता है कि आप शायद इसे दूसरे तरीके से करना चाहते थे क्योंकि मुझे लगता है कि आपके पास SessionsTableViewController में टेबल व्यू है।

तो, आपको SessionsTableViewController (शायद आपके मामले में "फ़ाइल का स्वामी") के उदाहरण के लिए dataSource अपनी तालिका दृश्य की संपत्ति को संलग्न करने की आवश्यकता है।

+0

मैं देख रहा हूँ, मैं अपने बजाय tableview मेरी TableViewController, धन्यवाद के लिए कस्टम वर्ग के रूप में मेरी SessionsTableViewController निर्धारित किया है, यह मैं क्या देख रहा था है सबकुछ अब काम करता है। –

0

यह सुनिश्चित करने के लिए जांचें कि आपने मॉड्यूल लेबल वाले बॉक्स में गलत ऐप निर्दिष्ट नहीं किया है (केवल कक्षा के अंतर्गत)। यह यूआई बिल्डर में पहचान निरीक्षक में है।

आपको सामान्य रूप से मॉड्यूल के रूप में निर्दिष्ट कुछ भी नहीं होना चाहिए, क्योंकि यह "वर्तमान ...." लेबल वाली भूरे रंग की प्रविष्टि के लिए डिफ़ॉल्ट है, जिसका अर्थ है कि यह सभी ऐप्स में उपलब्ध है। लेकिन, अगर आपने यहां एक ऐप निर्दिष्ट किया है, तो यूआई आइटम आपके प्रोजेक्ट के किसी अन्य ऐप के लिए उपलब्ध नहीं होगा, जब आप अन्य ऐप्स चलाने की कोशिश करते हैं तो आपको विषय त्रुटि संदेश देते हैं।

वह मेरी समस्या यह थी ...

+0

यदि यह टिप्पणी प्रश्न का उत्तर देती है, तो यह तुरंत स्पष्ट नहीं होता है कि कैसे। Rewording पर विचार करें? –

+1

मुझे नहीं पता कि मैं इसे और कैसे कह सकता हूं। यदि आपके पास मॉड्यूल में निर्दिष्ट कुछ भी है, तो आप एक और मॉड्यूल बनाने का प्रयास करते समय ओपी निर्दिष्ट त्रुटि प्राप्त करेंगे। –

संबंधित मुद्दे