对 IBAction 上的 NSFetchedResultsController 进行排序
我想在我的表格视图中对数据进行排序。我有带有 IBAction 的 UIButtons 来调用排序。
我创建了一个包含 sortKey 的字符串。我正在设置键并再次调用 fetchedResultsController,对表视图进行排序。
问题是,未调用 fetchedResultsController 方法,并且排序不起作用。
这是我的代码:
- (IBAction) actionSortCardColor:(id) sender {
XLog(@"");
sortString = @"colorOrder";
[self fetchedResultsController];
[self actionRemoveSortView:sender];
}
这是我的 fetchedResultsController 方法:
- (NSFetchedResultsController *)fetchedResultsController
{
[...]
NSPredicate *inboxPred = [NSPredicate predicateWithFormat:@"archived == 0"];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
[fetchRequest setPredicate:inboxPred];
XLog(@"sortString: %@", sortString);
if (sortString == nil) {
sortString = [[NSString alloc] initWithString:@"sortingOrder"];
}
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"setTitle" ascending:YES] autorelease];
NSSortDescriptor *sortDescriptor2 = [[[NSSortDescriptor alloc] initWithKey:sortString ascending:YES] autorelease];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor, sortDescriptor2, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];
[...]
}
i want to sort my Data in my Tableview. I have UIButtons with IBAction to call the sort.
I have created a string which contains the sortKey. I am setting the the key and call the fetchedResultsController again, to sort the tableview.
Problem is, fetchedResultsController method is not called and the sorting doesnt work.
here is my code:
- (IBAction) actionSortCardColor:(id) sender {
XLog(@"");
sortString = @"colorOrder";
[self fetchedResultsController];
[self actionRemoveSortView:sender];
}
Here my fetchedResultsController method:
- (NSFetchedResultsController *)fetchedResultsController
{
[...]
NSPredicate *inboxPred = [NSPredicate predicateWithFormat:@"archived == 0"];
// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];
[fetchRequest setPredicate:inboxPred];
XLog(@"sortString: %@", sortString);
if (sortString == nil) {
sortString = [[NSString alloc] initWithString:@"sortingOrder"];
}
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"setTitle" ascending:YES] autorelease];
NSSortDescriptor *sortDescriptor2 = [[[NSSortDescriptor alloc] initWithKey:sortString ascending:YES] autorelease];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor, sortDescriptor2, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];
[...]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里让表视图了解这些更改?您需要重新加载表视图实例的数据
[tableView reloadData];
当您将 __fetchedResultsController 设置为 nil 时,它无法使用任何更改更新 UITable 视图,因为它不在范围内。
Where is it that you let the table view know about these changes? You'll need to reload the data for your table view instance
[tableView reloadData];
When you set the __fetchedResultsController to nil, it cannot update the UITable view with any changes because it isn't in scope.