I am trying to reload my tableview with the parameters received from changing a UIDatepicker
. Currently I have the following method that captures the data and sends it to the UIButton
(which works). I am trying to reset the container view that houses the UITableViewController which is called DisplayTableViewController
but it is not reloading the NSFetchController
. Any suggestions about how to debug or fix this issue?
-(void)changeDate:(UIDatePicker *)sender {
//NSDate Formatter
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyy"];
//Convert to string
NSString *stringFromDate = [dateFormatter stringFromDate:sender.date];
//Send to UIButton
[dateLabel setTitle:stringFromDate forState:UIControlStateNormal];
DisplayTableViewController *tbc = (DisplayTableViewController *)self.childViewControllers[0];
[tbc.tableView reloadData];
}
EDIT
if ([[segue identifier] isEqualToString:@"ShowDisplayResults"])
{
//Format Date for Seague
NSDateFormatter *todaysdate = [[NSDateFormatter alloc] init];
[todaysdate setDateFormat:@"ddMMyyyy"];
//Convert to string for Seague
NSString *stringFromDate = [todaysdate stringFromDate:[NSDate date]];
// Store the text we entered to dateSeague
dateSeague =stringFromDate;
// Get reference to the destination view controller
DisplayTableViewController *targetVC = [segue destinationViewController];
// Pass any objects to the view controller here, like...
targetVC.dateSeague = dateSeague;
targetVC.Ex = self.Ex;
}
NSFETCHCONTROLLER IN CONTAINER
- (NSFetchedResultsController *)fetchedResultsController {
NSLog(@"Test Date for second seague = %@", dateSeague);
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
//Query Entity
NSEntityDescription *entity = [NSEntityDescription entityForName:@"WorkoutDetails"inManagedObjectContext:managedObjectContext];
//Fetch Entity
[fetchRequest setEntity:entity];
//Sort Returned Values
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"weight" ascending:NO];
//Fetch Sorted Array
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
//Set Return Size
[fetchRequest setFetchBatchSize:20];
//Predicate Results Based on ID
NSPredicate *sortName = [NSPredicate predicateWithFormat:@"exid == %@", Ex.name];
//Get NSDate format from String
NSString *stringFromDate = dateSeague;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
//Convert Back to NSDate
[df setDateFormat:@"ddMMyyyy"];
NSDate *inputedDate = [df dateFromString: stringFromDate];
//Set Predicate
NSPredicate *sortDate = [NSPredicate predicateWithFormat:@"date == %@", inputedDate];
//Compound Predicate Array
NSPredicate *placesPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:sortName, sortDate, nil]];
//Fetch Predicate Compound Array
[fetchRequest setPredicate:placesPredicate];
//Continue Fetching!
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:managedObjectContext sectionNameKeyPath:nil
cacheName: nil];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}