我從數據庫中獲取數據,我需要添加字符串字段值和記錄ID。NSMutableDictionary混淆瞭如何使用密鑰與某些代碼?
不過,我需要這與一些現有的代碼工作...
我更換這(見下面的代碼),並從我的數據庫獲取數據。
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.allCategories = dict;
[dict release];
這是它加載的文件...
但需要與這些鍵和值的搜索功能工作。
- (void)resetSearch {
NSMutableDictionary *allCategoriesCopy = [self.allCategories mutableDeepCopy];
self.Categories = allCategoriesCopy;
[allCategoriesCopy release];
NSMutableArray *keyArray = [[NSMutableArray alloc] init];
[keyArray addObject:UITableViewIndexSearch];
[keyArray addObjectsFromArray:[[self.allCategories allKeys]
sortedArrayUsingSelector:@selector(compare:)]];
self.keys = keyArray;
[keyArray release];
}
。
- (void)handleSearchForTerm:(NSString *)searchTerm {
NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
[self resetSearch];
for (NSString *key in self.keys) {
NSMutableArray *array = [Categories valueForKey:key];
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (NSString *name in array) {
if ([name rangeOfString:searchTerm
options:NSCaseInsensitiveSearch].location
== NSNotFound)
[toRemove addObject:name];
}
if ([array count] == [toRemove count])
[sectionsToRemove addObject:key];
[array removeObjectsInArray:toRemove];
[toRemove release];
}
[self.keys removeObjectsInArray:sectionsToRemove];
[sectionsToRemove release];
[table reloadData];
}
不斷收到來自該代碼中的錯誤...
NSDictionary *arrayTmp= [[NSDictionary alloc] init];
... loop records
int cid = sqlite3_column_int(statementTMP, 0);
NSString *category = [[NSString alloc]
initWithUTF8String:(char *)sqlite3_column_text(statementTMP, 1)];
[arrayTmp setObject:category forKey:[NSString stringWithFormat:@"%i", cid]];
錯誤造成的線之上
*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是:「 - [ NSCFString count]:無法識別的選擇器發送到實例0x4d4c500'*第一次調用時的調用堆棧*
... end loop
self.allCategories = arrayTmp;
[arrayTmp release];
我剛看過一個文件,看看我上面的編輯,圖像......我認爲那將是根?我應該怎麼做才能解決這個問題? – Jules 2011-01-14 15:04:41