0

I'm trying to limit the sections shown based on user input.

This part of my app resembles Apple's Custom Section Titles example a lot. Apple's example shows sections by month and year.

I want to filter these results by a user selected input.

For example: The user selects he only wants to view data from the month of May. Using a AND predicate on the FRC is not possible because I'm using a transient property.

Should I just hide sections that are not equal to @"may 2014" in the

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

method for example or is there a more correct way of doing this?

Perhaps a new transient property for each month that only returns for its respective month?

I feel like there is a guideline I should follow :)

BossBols
  • 175
  • 12

1 Answers1

0

Should I just hide sections that are not equal to @"may 2014" in the

In this realization (Apple's Example) this is a best way. If you use the same realization as in example:

NSInteger numericSection = [[theSection name] integerValue];
NSInteger year = numericSection / 1000;
NSInteger month = numericSection - (year * 1000);

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.year = year;
dateComponents.month = month;
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];

NSString *titleString = [formatter stringFromDate:date];

So, you can either check for string to be equal to @"may 2014", or just compare User selected month number to calculated month variable and if they are the same - use this section. Otherview skip section.