UA-17470720-3

Jump to content


Photo
- - - - -

Sort Section Titles


  • Please log in to reply
3 replies to this topic

#1 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 29 March 2016 - 05:12 AM

sorting sections does not seem to work anymore

 

the following code is am example

 

when this is run on the simulator sections sort CORRECTLY.. they sort from newest dates to oldest dates

 

BUT when run on a real device this does not work.. it will ONLY display sections from oldest > newest.. and no matter what sort setting or ascending setting that changes, it is always sorted oldest > newest

 

and i want it to sort like the sim, Newest > Oldest

 

    SCArrayOfObjectsModel *model = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView];
    model.autoSortSections = YES;
    //model.dataFetchOptions.sort = TRUE;  // enable sort
    model.dataFetchOptions.sortKey = @"timeStamp";
    model.dataFetchOptions.sortAscending = NO;
    
    self.dateFormatter = [[NSDateFormatter alloc] init];
    [self.dateFormatter setDateFormat:@"EEE d MMM yyyy"];
    
  
    model.sectionActions.didFetchItemsFromStore = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items)
    {
        // This is not the only way to sort, but probably the easiest when using STV
        SCDataFetchOptions *fetchOptions = [SCDataFetchOptions optionsWithSortKey:@"timeStamp" sortAscending:NO filterPredicate:nil];
        
        [fetchOptions sortMutableArray:items];
    };
    
    model.modelActions.sectionHeaderTitleForItem = ^NSString*(SCArrayOfItemsModel *itemsModel, NSObject *item, NSUInteger itemIndex)
    {
        NSDate *myDate = [item valueForKey:@"timeStamp"];
        
        FeedingListViewController *weakSelf = (FeedingListViewController*)[itemsModel viewController];
        
        return [weakSelf.dateFormatter stringFromDate:myDate];;
    };

    self.tableViewModel = model;

 

 

Oz

 

did some more testing and seem that its only the sim 6s Plus that and code changes change the sort order.. and other sim device or real device no matter the code setting sort old>new and never new>old


Edited by ozie, 29 March 2016 - 05:20 AM.

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 29 March 2016 - 11:28 AM

Hi Ozie,

 

I'm using similar code to sort a section:

 

    self.tableViewModel.sectionActions.didFetchItemsFromStore = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items) {
        DGBLog(@"self tableViewModel sectionActions didFetchItemsFromStore");
        NSSortDescriptor *dateSortDescriptor = [[NSSortDescriptor alloc] initWithKey:kdgGigDate ascending:NO];
        NSSortDescriptor *savedSortDescriptor = [[NSSortDescriptor alloc] initWithKey:kdgGigSaved ascending:NO];

        [items sortUsingDescriptors:@[dateSortDescriptor, savedSortDescriptor]];
    };

 

 

Both gigDate and gigSaved are NSDate from Core Data.

 

This works as expected, old > new with ascending:YES and new > old with ascending:NO and on these devices:

 

Simulator 6s Plus iSO 9.3

Simulator 6s iOS 9.3

6s iOS 9.3

 
STV 5.3.0
 
If you look at your items array before and after the sort is it actually being sorting?

Cheers,

Dave

www.dgapps.ie

#3 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 29 March 2016 - 10:48 PM

i expect the same.. but its just not happening

 

i even installed the same code on my iPad and its not sorting the same as the sim 6s.. it just does not sort no matter what i set in code

 

my code works like yours Dave when there is no  sectionHeaderTitleForItem code.. if there is things just don't work anymore

 

tried using the sort sections but that just crashes my app


Edited by ozie, 29 March 2016 - 11:20 PM.

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 29 March 2016 - 11:39 PM

after much playing.. got this going now.. WG had some code posted and when i used it i changed the sort sections key to what i thought had to be MY column key name and not headerTitle.. but leaving it as headerTitle worked

 

also had to change the formatting on the header string as of course Fri comes before Mon when alphabetically sorted

 

also change the to use model.sectionActions.didFetchItemsFromStore  code to sort like Dave suggested with nssortdescripter

 

SCArrayOfObjectsModel *model = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView];

    
    self.dateFormatter = [[NSDateFormatter alloc] init];
    [self.dateFormatter setDateFormat:@"yyyymmdd - EEE d MMMM"];
    
  
    model.sectionActions.didFetchItemsFromStore = ^(SCArrayOfItemsSection *itemsSection, NSMutableArray *items)
    {
        NSSortDescriptor *savedSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
        [items sortUsingDescriptors:@[savedSortDescriptor]];
        
    };
    
    model.modelActions.sortSections = ^(SCTableViewModel *tableModel, NSMutableArray *sections)
    {
        SCDataFetchOptions *fetchOptions = [SCDataFetchOptions optionsWithSortKey:@"headerTitle" sortAscending:NO filterPredicate:nil];
        
        [fetchOptions sortMutableArray:sections];
    };
    
    model.modelActions.sectionHeaderTitleForItem = ^NSString*(SCArrayOfItemsModel *itemsModel, NSObject *item, NSUInteger itemIndex)
    {
        NSDate *myDate = [item valueForKey:@"timeStamp"];
        
        FeedingListViewController *weakSelf = (FeedingListViewController*)[itemsModel viewController];
        
        return [weakSelf.dateFormatter stringFromDate:myDate];;
    };

  • Dave Guerin likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users