【问题标题】:Filter sections of NSFetchedResultsController with Transient sectionNameKeyPath使用 Transient sectionNameKeyPath 过滤 NSFetchedResultsController 的部分
【发布时间】:2014-07-30 01:08:12
【问题描述】:

我正在尝试根据用户输入限制显示的部分。

我的应用程序的这一部分与 Apple 的自定义部分标题示例非常相似。 Apple 的示例按月和年显示部分。

我想通过用户选择的输入过滤这些结果。

例如:用户选择他只想查看 5 月份的数据。 无法在 FRC 上使用 AND 谓词,因为我使用的是瞬态属性。

我是否应该在

中隐藏不等于 @"may 2014" 的部分?
 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

例如方法还是有更正确的方法?

也许每个月都有一个新的瞬态属性,只在各自的月份返回?

我觉得我应该遵循一个准则:)

【问题讨论】:

    标签: ios objective-c core-data nsfetchedresultscontroller transient


    【解决方案1】:

    我是否应该只隐藏不等于 @"may 2014" 的部分

    在这种实现(Apple 的示例)中,这是最好的方法。 如果您使用与示例相同的实现:

    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];
    

    因此,您可以检查字符串是否等于 @"may 2014",或者仅将用户选择的月份数与计算的月份变量进行比较,如果它们相同 - 请使用此部分。其他查看跳过部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 2011-09-30
      相关资源
      最近更新 更多