我正在尝试使用具有混合语言数据的FRC并希望有一个节索引.
似乎从文档中你应该能够覆盖FRC
- (NSString *)sectionIndexTitleForSectionName:(NSString *)sectionName
- (NSArray *)sectionIndexTitles
Run Code Online (Sandbox Code Playgroud)
然后使用UILocalizedIndexedCollation来获得本地化的索引和节.但遗憾的是,这不起作用,并不是打算使用的:(
有没有人能够使用带有UILocalizedIndexedCollation的FRC,或者我们被迫使用示例UITableView + UILocalizedIndexedCollation示例中提到的手动排序方法(示例代码包含在我工作的地方).
使用以下属性
@property (nonatomic, assign) UILocalizedIndexedCollation *collation;
@property (nonatomic, assign) NSMutableArray *collatedSections;
Run Code Online (Sandbox Code Playgroud)
和代码:
- (UILocalizedIndexedCollation *)collation
{
if(collation == nil)
{
collation = [UILocalizedIndexedCollation currentCollation];
}
return collation;
}
- (NSArray *)collatedSections
{
if(_collatedSections == nil)
{
int sectionTitlesCount = [[self.collation sectionTitles] count];
NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount];
collatedSections = newSectionsArray;
NSMutableArray *sectionsCArray[sectionTitlesCount];
// Set up the sections array: elements are mutable arrays that will contain the …Run Code Online (Sandbox Code Playgroud) localization core-data nsfetchedresultscontroller ios uilocalizedcollation
在这里尝试解决方案:https: //stackoverflow.com/questions/1741093?tab = nenene #tab-top
我正在使用瞬态属性和类别解决方案,它似乎正在工作,直到索引char再次开始绕回A,不知道它为什么这样做,只记录类别/瞬态getter返回的内容uppercaseFirstLetterOfName.
我正在使用name属性进行排序,然后将fetchRequest上的sectionNameKeyPath设置为uppercaseFirstLetterOfName.
完整错误是:NSFetchedResultsController错误:索引248处的获取对象具有无序部分名称'Y.对象必须按节名称排序'
我可能出错的任何想法或如何追踪问题?
我正在尝试实现支持索引的Core Data支持的UITableView(例如:出现在侧面的字符,以及与它们一起出现的节标题).在没有Core Data的情况下,我没有遇到任何问题:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
Run Code Online (Sandbox Code Playgroud)
在没有使用索引的情况下实现由Core Data支持的UITableView也没有问题.
我想弄清楚的是如何优雅地将两者结合起来?显然,一旦索引和重新分区内容,就不能再使用标准的NSFetchedResultsController来检索给定索引路径的内容.所以我将索引字母存储在NSArray中,将我的索引内容存储在NSDictionary中.这一切都适用于显示,但在添加和删除行时我有一些真正的麻烦,特别是如何正确实现这些方法:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller;
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath;
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type;
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller;
Run Code Online (Sandbox Code Playgroud)
因为它返回的索引路径与核心数据中的索引路径没有相关性.当用户添加一行时,我通过简单地重建我的索引NSArray和NSDictionary来添加工作,但是当他们删除一个时,执行相同操作会导致整个应用程序崩溃.
是否有一个简单的模式/示例我在这里缺少使所有这些工作正常?
编辑:只是为了澄清我知道NSFetchedResultsController是开箱即用的,但我想要的是复制像Contacts应用程序这样的功能,其中索引是该人名的第一个字母.
iphone core-data uitableview nsfetchedresultscontroller cocoa-design-patterns