TableView doesnt show any Data(CoreData) - App crashe

Posted by brush51 on Stack Overflow See other posts from Stack Overflow or by brush51
Published on 2011-01-05T16:49:45Z Indexed on 2011/01/05 16:54 UTC
Read the original article Hit count: 201

Hey @all,

i cant read my data from my database. I have an app with a tabbarcontroller. in the first tab the iphone camera takes a picture from a barcode and send the result to another view (CameraReturnDetailViewController). In CameraReturnDetailViewController is the savebutton, and here is the code from this save button:

- (IBAction)saveAndQuitScan:(id) sender {
    XLog(@"saveAndQuitScan button wurde geklickt!");

    ProjectQRCodeAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSManagedObject *newData;

    newData = [NSEntityDescription insertNewObjectForEntityForName:@"BarcodeDaten"     inManagedObjectContext:context];

    [newData setValue:dataLabel.text forKey:@"Barcode_CD"];

    NSError *error;
    [context save:&error];

    //Aktuelle ansicht (self) animiert verlassen
    [self dismissModalViewControllerAnimated:YES];

    // Nachdem die ansicht verlassen wurde, 
    // auf das zweite Tab wechseln(scanverlauf)
    /** TO DO - Funktioniert noch nicht **/
    [self.tabBarController setSelectedIndex:1]; 
}  

Now, my aim is to show the taba in the second tab, in a TableView (ScansViewController):

- (void)viewDidLoad {
[super viewDidLoad];

if (managedObjectContext_ == nil) 
    { 
managedObjectContext_ = [(ProjectQRCodeAppDelegate *)[[UIApplication sharedApplication]delegate] managedObjectContext]; 
NSLog(@"After managedObjectContext: %@",  managedObjectContext_);
}

myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;

myTableView.autoresizesSubviews = YES;

    self.navigationItem.title = @"Code Liste";

    self.view = myTableView;    

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
    return [itemsList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView     dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

return cell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *selectDay = [NSString stringWithFormat:@"%d", indexPath.row];

    TableDetailViewController *fvController = [[TableDetailViewController alloc] initWithNibName:@"TableDetailViewController" bundle:[NSBundle mainBundle]];
    fvController.selectDay = selectDay;
    [self.navigationController pushViewController:fvController animated:YES];
    [fvController release];
    fvController = nil;

}

- (void) configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {

    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = [[managedObject valueForKey:@"Barcode_CD"] description];
}

- (NSFetchedResultsController *) fetchedResultsController {


    if (fetchedResultsController_ !=nil) {
        return fetchedResultsController_;
    }


    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"BarcodeDaten"     inManagedObjectContext:self.managedObjectContext];

    [fetchRequest setEntity:entity];
    [fetchRequest setFetchBatchSize:20];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Barcode_CD"     ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc]     initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext     sectionNameKeyPath:nil cacheName:@"Root"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor release];
    [sortDescriptors release];

NSError *error = nil;
    if (![fetchedResultsController_ performFetch:&error]) {
        XLog(@"Error: %@, %@", error, [error userInfo]);
        abort();
    }

return fetchedResultsController_;
}  

At first i get this error when i choosed the second tab(ScansViewController): " Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'BarcodeDaten'' "

The Name is correct but i dont understand my mistake.

No data is showed in the Tableview, why?

Have I missed something..? Or something wrong?

Thanks for help, brush51

© Stack Overflow or respective owner

Related posts about uitableview

Related posts about core-data