Hallo,
Ich weiß nicht wieso und ich suche den Fehler schon sehr lange, aber mein TableView will sich einfach nicht aktualisieren, wenn der Controller wieder aufgerufen wird.
In der Console sehe ich, dass die neuen Daten eingelesen werden, aber dennoch wird der alte Datenbestand angezeigt.
Ich weiß nicht an was es liegen könnte
Alles anzeigen
Vielen vielen Dank im Voraus
Ich weiß nicht wieso und ich suche den Fehler schon sehr lange, aber mein TableView will sich einfach nicht aktualisieren, wenn der Controller wieder aufgerufen wird.
In der Console sehe ich, dass die neuen Daten eingelesen werden, aber dennoch wird der alte Datenbestand angezeigt.
Ich weiß nicht an was es liegen könnte
Quellcode
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.managedObjectContext = [(AppDelegate *) [[UIApplication sharedApplication] delegate] managedObjectContext];
- if (managedObjectContext != nil) {
- NSLog(@"ist nicht nil");
- }
- else
- {
- NSLog(@"Ist nil");
- }
- NSError *error;
- if (![[self fetchedResultsController] performFetch:&error]) {
- // Update to handle the error appropriately.
- NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
- exit(-1); // Fail
- }
- }
- - (NSFetchedResultsController *)fetchedResultsController {
- if (_fetchedResultsController != nil) {
- return _fetchedResultsController;
- }
- NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
- NSEntityDescription *entity = [NSEntityDescription
- entityForName:@"TrimmModelDetails" inManagedObjectContext:managedObjectContext];
- [fetchRequest setEntity:entity];
- NSSortDescriptor *sort = [[NSSortDescriptor alloc]
- initWithKey:@"date" ascending:NO];
- [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
- [fetchRequest setFetchBatchSize:20];
- NSFetchedResultsController *theFetchedResultsController =
- [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
- managedObjectContext:managedObjectContext sectionNameKeyPath:nil
- cacheName:nil];
- self.fetchedResultsController = theFetchedResultsController;
- _fetchedResultsController.delegate = self;
- return _fetchedResultsController;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- return 1;
- }
- - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
- TrimmModelDetails *details = [_fetchedResultsController objectAtIndexPath:indexPath];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"dd.MM.yyyy"];
- cell.textLabel.text = details.wind;
- cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ ; %@",details.rating,[dateFormatter stringFromDate:details.date]];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- id sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];
- return [sectionInfo numberOfObjects];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell =
- [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- // Set up the cell...
- [self configureCell:cell atIndexPath:indexPath];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // Navigation logic may go here. Create and push another view controller.
- UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
- DetailViewController *detailviewcontroller = [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
- TrimmModelDetails *details = [_fetchedResultsController objectAtIndexPath:indexPath];
- detailviewcontroller.detailItem = details;
- // ...
- // Pass the selected object to the new view controller.
- [self.navigationController pushViewController:detailviewcontroller animated:YES];
- }
- - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
- // The fetch controller is about to start sending change notifications, so prepare the table view for updates.
- [self.tableView beginUpdates];
- }
- - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
- UITableView *tableView = self.tableView;
- switch(type) {
- case NSFetchedResultsChangeInsert:
- [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- break;
- case NSFetchedResultsChangeDelete:
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- break;
- case NSFetchedResultsChangeUpdate:
- [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
- break;
- case NSFetchedResultsChangeMove:
- [tableView deleteRowsAtIndexPaths:[NSArray
- arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- [tableView insertRowsAtIndexPaths:[NSArray
- arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- break;
- }
- }
- - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id )sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
- switch(type) {
- case NSFetchedResultsChangeInsert:
- [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
- break;
- case NSFetchedResultsChangeDelete:
- [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
- break;
- }
- }
- - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
- // The fetch controller has sent all current change notifications, so tell the table view to process all updates.
- [self.tableView endUpdates];
- }
Vielen vielen Dank im Voraus
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von BigStorm ()