Xcode 如何限制NSFetchResultsController中的对象数?

Xcode 如何限制NSFetchResultsController中的对象数?,xcode,tableview,nsfetchedresultscontroller,Xcode,Tableview,Nsfetchedresultscontroller,我有一个NSFetchedResultsController,需要在tableView中显示数据 我使用NSFetchedResultsControllerDelegate - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { DLog(@"controllerWillChangeContent: %@", controller); [self.tableViewA begin

我有一个NSFetchedResultsController,需要在tableView中显示数据

我使用NSFetchedResultsControllerDelegate

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    DLog(@"controllerWillChangeContent: %@", controller);
    [self.tableViewA beginUpdates];

}


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {

    DLog(@"didChangeSection: %@", controller);

    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.tableViewA insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.tableViewA deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}


- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath {

    DLog(@"controller:%@\ndidChangeObject:%@\natIndexPath:%@\nforChangeType:%d\nnewIndexPath:%@\n",controller, anObject, indexPath, type, newIndexPath);

    UITableView *tableView = self.tableViewA;
    DLog(@"%@", self.tableViewA);
    switch(type) {
        case NSFetchedResultsChangeInsert:
                [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationRight];
            break;

        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
            break;

        case NSFetchedResultsChangeUpdate:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
            //[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
            break;

        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationRight];
            break;
    }

}


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.tableViewA endUpdates];
}
这意味着我只想显示100个数据,但当我执行一些操作使NSManagedObjectContext发生更改时,它将调用NSFetchedResultsControllerDelegate并将任何数据插入tableView。问题是,tableView可以显示100多个数据

我使用此函数设置numberOfRowsInSection

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.FetchController sections] objectAtIndex:section];
    CalledRowCountingNotYetCallRowForSection=true;
    [self.tableViewA setBounces:YES];


    if([sectionInfo numberOfObjects]>100){
        //[Timer searchCriteriaChanged];
        CLog(@"Something Wrong This NumberOfRow: %d", [sectionInfo numberOfObjects]);
    }
    else{
    }
    return [sectionInfo numberOfObjects];
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
id sectionInfo=[[self.FetchController sections]objectAtIndex:section];
CalledRowCountingNotYetCallRowForSection=true;
[self.tableViewA挫折盎司:是];
如果([sectionInfo numberOfObjects]>100){
//[计时器搜索标准已更改];
阻塞(@“此号码行有问题:%d”,[sectionInfo numberOfObjects]);
}
否则{
}
返回[sectionInfo numberOfObjects];
}
如何使tableView显示的数据不能超过100个

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
调用此函数不是为了设置numberOfRowsInSection,而是为了获取号码

-(void)controller:(NSFetchedResultsController *)controller 
       didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
       atIndex:(NSUInteger)sectionIndex 
       forChangeType:(NSFetchedResultsChangeType)type {

DLog(@"didChangeSection: %@", controller);

switch(type) {
    case NSFetchedResultsChangeInsert:
   if([YourtableView numberOfRowsInSection:yourSection]>100){
      return;  //TO avoid insertion 
   }
   ...
   ...
   ...
 }
}
-(void)控制器:(NSFetchedResultsController*)控制器
didChangeSection:(id)sectionInfo
atIndex:(整数)sectionIndex
forChangeType:(NSFetchedResultsChangeType)类型{
DLog(@“didChangeSection:%@”,控制器);
开关(类型){
案例NSFetchedResultsChangesInsert:
如果([YourtableView numberOfRowsInSection:yourSection]>100){
return;//避免插入
}
...
...
...
}
}
调用此函数不是为了设置numberOfRowsInSection,而是为了获取号码

-(void)controller:(NSFetchedResultsController *)controller 
       didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
       atIndex:(NSUInteger)sectionIndex 
       forChangeType:(NSFetchedResultsChangeType)type {

DLog(@"didChangeSection: %@", controller);

switch(type) {
    case NSFetchedResultsChangeInsert:
   if([YourtableView numberOfRowsInSection:yourSection]>100){
      return;  //TO avoid insertion 
   }
   ...
   ...
   ...
 }
}
-(void)控制器:(NSFetchedResultsController*)控制器
didChangeSection:(id)sectionInfo
atIndex:(整数)sectionIndex
forChangeType:(NSFetchedResultsChangeType)类型{
DLog(@“didChangeSection:%@”,控制器);
开关(类型){
案例NSFetchedResultsChangesInsert:
如果([YourtableView numberOfRowsInSection:yourSection]>100){
return;//避免插入
}
...
...
...
}
}