1

I have sorted my object array, idea of entity employee having attribute dateOfentry, name, age.

NSSortDescriptor *ageDescriptor =
    [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];
NSArray *sortDescriptors = @[ageDescriptor];
NSArray *sortedArray = [empArrayList sortedArrayUsingDescriptors:sortDescriptors];

Now in a day employe can enter many times with time difference, so i like to fetch and display date bases records of employee visito .

How I can proceed further to collect same day records with different records so I can display it in table view with section as date of the day with row as timing .

Ben S
  • 68,394
  • 30
  • 171
  • 212
terminator
  • 95
  • 1
  • 6

2 Answers2

0

Just add :

-(void)viewWillAppear:(BOOL)animated {
   [tableView reloadData];
}

Maybe it works.

Ben S
  • 68,394
  • 30
  • 171
  • 212
Abha
  • 1,032
  • 1
  • 13
  • 36
0

I suppose sorting by date works correctly.

If you want your function to collect all Objects with a specific date, it could look like this (assuming your object employee is a NSDictionary or NSMutableDictionary);

-(NSArray*)getObjectsWithDate: (NSDate*) date fromArray:(NSArray*) array
{
    NSMutableArray *retArray = [[NSMutableArray alloc]init];
    BOOL b_enteredCorrectDateArea = NO;
    for (NSDictionary *dict in array) {
        NSDate *dateFromDict = [dict objectForKey:@"date"];
        //Updated section
        unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
        NSCalendar* calendar = [NSCalendar currentCalendar];
        NSDateComponents* components = [calendar components:flags fromDate:dateFromDict];
        NSDate* dateFromDictWithoutTimeComponent = [calendar dateFromComponents:components];

        components = [calendar components:flags fromDate:date];
        NSDate *dateFromArgumentsWithoutTimeComponent = [calendar dateFromComponents:components];
        //end of update

        if ([dateFromArgumentsWithoutTimeComponent isEqualToDate:dateFromDictWithoutTimeComponent]) {
            [retArray addObject:dict];
            if (!b_enteredCorrectDateArea) {
                b_enteredCorrectDateArea = YES;
            }
        }
        else if(b_enteredCorrectDateArea) //performance Optimization
        {
            break;
        }
    }
    return retArray;
}

If you then want to display your filtered Data, just use the returned Array as datasource for your UITableView and reload the tableview after assigning the array as datasource.

Of course this is not tested, since i have not test-data. But it should work like this.

If this works for you, please do also upvote this post, since it showed me, how to just use the date without time. :)

Community
  • 1
  • 1
Maverick1st
  • 3,774
  • 2
  • 34
  • 50
  • its good, but please understand, like i have 5 or more(dynamic) records, i fetched all records from data base and i waan to display same date records with different time in one sections and other date records with different time in other section same on ,thanks please help me out – terminator Mar 07 '13 at 10:14
  • ah. so you want to compare just the date, and not the time. Ok, sorry, misunderstood that. I will update my answer then. – Maverick1st Mar 07 '13 at 10:16
  • hello Maverick,please suggest if you could i do this in my coding @interface FBCDMasterViewController : UITableViewController , its giving error:Cannot find protocol declaration for 'NSFetchedResultsControllerDelegate' – terminator Mar 07 '13 at 10:34
  • For this you'd better write a new Question, since it is another error. Usually this error means you forgot to import the header of the class whose declaration is not found. Maybe just googling the error would serve you better to fix this. – Maverick1st Mar 07 '13 at 10:38