使用NSFetchedResultController如何确保只显示100行

发布于 2024-12-15 00:00:38 字数 928 浏览 2 评论 0 原文

request.fetchLimit = 100;
request.fetchBatchSize = 100;

是否真的使用该函数通过 NSFetchedResultsControllerDelegate 来限制 tableView 的行数?

但问题是..有时表会显示超过 100 行,但是当我更改页面并返回表时,表将仅显示 100 行,这是怎么回事?我不希望表格显示超过 100 个。

提前谢谢您。

另一种方法是

更新,

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

以便当 numberOfObjects 大于 100 时,行数变为 100。但是,这会干扰

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject

那么你该怎么做呢?

request.fetchLimit = 100;
request.fetchBatchSize = 100;

is it true use that function to make limit for how many rows at tableView with NSFetchedResultsControllerDelegate?

but the problem is.. sometime the table will show more than 100 rows, but when I change the page and back to the table, the table will show just 100 rows, how can it be? I don't want the table can show more than 100.

thank you in advanced.

Another way to do it is to do

is to update

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

so that when numberOfObjects is bigger than 100, then the number of row becomes 100. However, that interfere with

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject

So how do you do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥︴琐丶欲为 2024-12-22 00:00:38

您可以通过覆盖表视图数据源的 numberOfSectionsInTableViewnumberOfRowsInSection 函数(分别返回 1 和 100)来限制可用行数。

您是否使用SQLStore作为表的基础?根据苹果文档( http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSFetchRequest_Class/NSFetchRequest.html#//apple_ref/doc/c_ref/NSFetchRequest ),fetchLimit 仅适用于 SQL 存储。

You could limit the amount of available rows by overriding the numberOfSectionsInTableView and numberOfRowsInSection functions of your table view data source, returning 1 and 100, respectively.

Are you using a SQLStore as base for your table? According to apple documentation ( http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSFetchRequest_Class/NSFetchRequest.html#//apple_ref/doc/c_ref/NSFetchRequest ), fetchLimit does only work for SQL stores.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文