我得到的值是從plist中排序並顯示在tableview
中的值。我正在提供輸入將寫入plist的自定義類別的功能。但我希望按照排序的字母順序插入。有人可以建議我如何獲得必須插入的行的indexpath
。我已經使用了下面的代碼,自定義項將在0位置在Sorted Array中獲取IndexPath
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];
***終止應用程序由於未捕獲的異常「NSUnknownKeyException」,原因:'[<__ NSCFString 0x8b7e580> valueForUndefinedKey:]:這個類不是關鍵字編碼密鑰值。「 – 2013-04-24 06:46:47
當使用排序描述符時,我得到了上述錯誤 – 2013-04-24 06:47:42
@ChandraSekhar你可以把斷點,告訴我你的代碼破壞的地方。 self.categoriesArray只包含字典對象,它們都有一個關鍵的「名稱」,我假設這些都是這樣的。請檢查,以及 – Anupdas 2013-04-24 06:56:55