Setting UITableView headers from NSFetchedResultsController

后端 未结 2 425
清酒与你
清酒与你 2021-01-18 03:14

I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext. I\'m using the results to populate a UITableView.

2条回答
  •  情书的邮戳
    2021-01-18 03:55

    I ended up adding a new property day to my NSManagedObject subclass to get a formatted date string.

    @property (nonatomic, readonly) NSString * day;
    @property (nonatomic, retain) NSDateFormatter * dateFormatter
    

    Sythesize the dateFomatter. @synthesize dateFormatter;

    I initialize the date formatter in awakeFromFetch and awakeFromInsert.

    self.dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [self.dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    

    The accessor for day.

    - (NSString *)day {
      NSDate *date = self.startDate;
      return [self.dateFormatter stringFromDate:date];
    }
    

    I then set my section name keypath to look at day; you shouldn't need to make any changes to your sort descriptors.

提交回复
热议问题