objective-c - 对 Core Data 中的特定部分进行排序
<p><p>我正在使用 NSFetchedResultsController 来填充我的应用程序的 tableView,它是按部分分组的(在这种情况下,我的核心数据对象中的类别属性)我想手动重新排序部分,而不是按字母顺序。</p>
<p>下面是我到目前为止所做的代码</p>
<pre><code>- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [ init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Media" inManagedObjectContext:_context];
;
NSSortDescriptor *sort = [
initWithKey:@"category" ascending:NO];
];
;
NSFetchedResultsController *theFetchedResultsController =
[ initWithFetchRequest:fetchRequest
managedObjectContext:_context sectionNameKeyPath:@"category"
cacheName:@"Root"];
self.fetchedResultsController = theFetchedResultsController;
_fetchedResultsController.delegate = self;
return _fetchedResultsController;
}
</code></pre>
<p>提前致谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果任务是提供部分的自定义顺序,那么您可以继承 NSFetchedResultsController 并实现</p>
<pre><code>- (NSInteger)sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)sectionIndex;
</code></pre>
<p>如果需要的话</p>
<pre><code>@property (nonatomic, readonly) NSArray *sectionIndexTitles;
- (NSString *)sectionIndexTitleForSectionName:(NSString *)sectionName;
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - 对 Core Data 中的特定部分进行排序,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/8559858/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/8559858/
</a>
</p>
页:
[1]