【发布时间】:2013-04-23 13:37:18
【问题描述】:
我正在获取从 plist 中排序的值并将它们显示在 tableview 中。我提供了输入将写入 plist 的自定义类别的功能。但我希望按字母顺序插入。有人可以建议我如何获取必须插入的行的indexpath。我使用了以下代码,自定义条目将插入到 0 位置
NSInteger section = 0;
NSInteger row = 0;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
NSDictionary *categoryDictionary = [NSMutableDictionary dictionary];
[categoryDictionary setValue:newCategoryName forKey:@"name" ];
[categoryDictionary setValue:@"custom.png" forKey:@"image"];
[[self categoriesArray]insertObject:categoryDictionary atIndex:row];
[[self categoriesArray] writeToFile:[self dataFilePath] atomically:YES];
NSArray *indexPathsToInsert = [NSArray arrayWithObject:indexPath];
[[self tableView]insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationRight];
[self.categoriesArray writeToFile:[self dataFilePath] atomically:YES];
【问题讨论】:
标签: ios objective-c uitableview nsarray plist