Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView节标题导致表视图缓慢_Ios_Uitableview_Core Data_Nsfetchedresultscontroller - Fatal编程技术网

Ios UITableView节标题导致表视图缓慢

Ios UITableView节标题导致表视图缓慢,ios,uitableview,core-data,nsfetchedresultscontroller,Ios,Uitableview,Core Data,Nsfetchedresultscontroller,我有一个UITableView,它使用NSFetchedResultsController从核心数据加载实体。获取请求当前使用批处理大小来控制内存开销,因为从获取中返回了大约1000行。连接所有这些之后,表视图的速度非常快 我现在的问题是,我想在表视图中添加分组和节标题。我已经实现了所需的委托方法,但似乎在加载时正在为fetch中的每个可能的节调用tableView:titleForHeaderInSection:。我按日期分组,所以在整个表视图中大约有700个部分。正如您可能猜到的,这降低了我

我有一个
UITableView
,它使用
NSFetchedResultsController
从核心数据加载实体。获取请求当前使用批处理大小来控制内存开销,因为从获取中返回了大约1000行。连接所有这些之后,表视图的速度非常快

我现在的问题是,我想在表视图中添加分组和节标题。我已经实现了所需的委托方法,但似乎在加载时正在为fetch中的每个可能的节调用
tableView:titleForHeaderInSection:
。我按日期分组,所以在整个表视图中大约有700个部分。正如您可能猜到的,这降低了我的视图控制器的初始负载,因为它必须通过所有批处理获取我的部分标题。我希望这个方法能够像加载表视图单元格的方法一样被调用——当您在表中滚动时

是否有更好的方法加载节标题,或者更好的是,是否有一种方法可以将节标题的加载推迟到用户使用实际表格单元格滚动时进行

需要注意的一些事项:

  • 我正在使用
    setPropertiesToFetch:
    方法将获取请求告知预故障
    dateOfFlight
  • 提取请求的批处理限制为25
  • 提取请求没有提取限制
  • 我不需要章节索引标题。对于
    sectionIndexTitlesForTableView:
    ,我返回
    Nil
  • 从fetch返回的实体大约有1000个,因为我们按本地化日期分组,所以大约有700个部分
值得一提的是,下面是我用来加载章节标题的代码:

/**
 * We override this method from the base class because we need to format the date
 * prior to it being displayed in the UITableViewSection.
 * @author Jesse Bunch
 **/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    Flight *cellEntity = (Flight *)[[sectionInfo objects] objectAtIndex:0];

    if (cellEntity) {
        return [cellEntity.dateOfFlight localizedLongDateString];
    }

    return L(@"Unknown Date");

}
/**
*我们从基类重写这个方法,因为我们需要格式化日期
*在显示在UITableView部分之前。
*@作者杰西·邦奇
**/
-(NSString*)表格视图:(UITableView*)表格视图标题标题标题部分:(NSInteger)部分{
id sectionInfo=[[self.fetchedResultsController节]objectAtIndex:section];
Flight*cellEntity=(Flight*)[[sectionInfo对象]对象索引:0];
if(单元实体){
返回[cellEntity.dateOfFlight localizedLongDateString];
}
返回L(“未知日期”);
}
-

编辑 通过从节名而不是实体本身格式化日期,我确实实现了更快的速度:

/**
 * We override this method from the base class because we need to format the date
 * prior to it being displayed in the UITableViewSection.
 * @author Jesse Bunch
 **/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    static NSDateFormatter *dateFormatter;
    if(nil == dateFormatter) {
        dateFormatter = [[NSDateFormatter alloc] init];
        dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss ZZ";
    }

    id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    NSDate *sectionDate = [dateFormatter dateFromString:sectionInfo.name];  

    if (sectionDate) {
        return [sectionDate localizedLongDateString];
    }

    return L(@"Unknown Date");

}
/**
*我们从基类重写这个方法,因为我们需要格式化日期
*在显示在UITableView部分之前。
*@作者杰西·邦奇
**/
-(NSString*)表格视图:(UITableView*)表格视图标题标题标题部分:(NSInteger)部分{
静态NSDateFormatter*日期格式化程序;
if(nil==日期格式化程序){
dateFormatter=[[NSDateFormatter alloc]init];
dateFormatter.dateFormat=@“yyyy-MM-dd HH:MM:ss ZZ”;
}
id sectionInfo=[[self.fetchedResultsController节]objectAtIndex:section];
NSDate*sectionDate=[DateFormatterDateFromString:sectionInfo.name];
如果(日期){
返回[sectionDate localizedLongDateString];
}
返回L(“未知日期”);
}

您是否考虑过以增量方式加载和显示数据


我的意思是:加载一组数据并显示N行(使用N Do或help?Apple示例是一个有趣的方法,但它不是我所需要的。我已经考虑过了,这可能是我想走的路线。但是,我想知道如何告诉
NSFetchedResultsController
获取更多行并将它们添加到它所管理的数据的末尾?Unfo当然,我无法帮助您使用
NSFetchedResultsController
;我认为,无论如何,如果它不支持增量或基于范围的获取,您可以执行查询并缓存结果;然后从缓存中增量读取结果。关于更新表,您可以使用下面列出的方法表视图引用中的“插入、删除和移动行和节”:。