代码之家  ›  专栏  ›  技术社区  ›  eemceebee

coredata和uitableviewcontroller问题

  •  0
  • eemceebee  · 技术社区  · 16 年前

    我有一个应用程序可以处理核心数据。数据有一个带有日期的字段,我想在单独的部分中显示一个月的每个条目。

    我该如何获取数据?我使用nsfetchedresultsController获取数据并使用:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    {
    
        id <NSFetchedResultsSectionInfo> sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];
        return [sectionInfo numberOfObjects];
    
    }
    

    要获取行和此:

        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    MyInfoObject *info = [_fetchedResultsController objectAtIndexPath:indexPath];
    }
    

    获取我的实际数据对象。

    谢谢

    1 回复  |  直到 16 年前
        1
  •  1
  •   Travis    16 年前

    在实例化FetchedResultsController时,请确保设置了sectionNameKeyPath。

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"dateKey" cacheName:@"Root"];
    
    推荐文章