SETUP從的NSMutableDictionary獲取對象和UITableView的
顯示出來我有NSMutableDictionaries的一個NSMutableDictionary。我創建了搜索術語的字典,現在我想顯示它們。我使用了一種方法(如下)將包含搜索項的項目複製到另一個字典中。我知道它正在複製,因爲我可以打印字典並查看結果。同時顯示正確數量的行,但不顯示數據。我已經包含了複製字典的方法,以及字典在原始數組中的樣子以及它在新數組中的外觀。
問題
我拉項目從NSDictionaires的理解是不正確的。我已經閱讀了多個地方,我知道我想使用objectforkey。但我無法弄清楚如何從主要字典中獲取字典並顯示它們。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (searching) {
//ATTEMPT ONE
// NSDictionary *searchEmp = [copyListOfItems objectForKey:[copyListOfItems allkeys]];
// cell.textLabel.text = [[searchEmp objectForKey:kFULLNAME_TAG] objectAtIndex:indexPath.row];
//ATTEMPT TWO
NSString *name = [[copyListOfItems allKeys] objectAtIndex: indexPath.row];
NSString *value = [copyListOfItems objectForKey:path];
cell.textLabel.text = [copyListOfItems objectForKey:value];
}else{
NSDictionary *employee = [[self.orderedSections valueForKey:[[[self.orderedSections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.text = [employee objectForKey:kFULLNAME_TAG];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
這是我用於複製從一個的NSMutableDictionary到另一個
for (NSDictionary *emp in employeeData)
{
NSString *empName = [emp objectForKey:kFULLNAME_TAG];
NSRange titleResultsRange = [empName rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0){
NSLog(@"search result ---> %@" ,emp);
[copyListOfItems setValue:emp forKey:empName];
}
}
這是的NSMutableDictionary之前,我將其複製到了 「copyListofItems」
2 012-02-27 17:24:44.399 USSContacts[14514:10d03] search result ---> {
0 = JO;
1 = "Zary Joon";
10 = "N/A";
11 = "N/A";
2 = Joon;
3 = Zary;
4 = "N/A";
5 = "N/A";
6 = "N/A";
7 = "[email protected]";
8 = "N/A";
9 = "N/A";
BUID = "N/A";
Department = "N/A";
EmployeeId = JONZ;
Extension = "N/A";
FirstName = Zary;
FullName = "Zachary Joon";
LastName = Joon;
Mobile = "N/A";
Shift = "N/A";
Supervisor = "N/A";
Title = "N/A";
email = "[email protected]";
該方法
}
我試圖在UITableView中顯示的字典看起來像這樣。它是上述的副本。
<CFBasicHash 0x5c6aa10 [0x1175400]>{type = mutable dict, count = 1,
2 : <CFString 0x5c7cf20 [0x1175400]>{contents = "Zary Joon"} = <CFBasicHash 0x5c7d0a0 [0x1175400]>{type = mutable dict, count = 24,
0 : <CFString 0x7058790 [0x1175400]>{contents = "Shift"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
1 : <CFString 0x7054390 [0x1175400]>{contents = "Mobile"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
2 : <CFString 0x70543c0 [0x1175400]>{contents = "Title"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
4 : <CFString 0x7058ed0 [0x1175400]>{contents = "10"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
6 : <CFString 0x7054330 [0x1175400]>{contents = "Supervisor"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
8 : <CFString 0x7058100 [0x1175400]>{contents = "FirstName"} = <CFString 0x5c7d2a0 [0x1175400]>{contents = "Zary"}
9 : <CFString 0x7058f80 [0x1175400]>{contents = "11"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
13 : <CFString 0x7051a70 [0x1175400]>{contents = "0"} = <CFString 0x5c7c100 [0x117500]>{contents = "J"}
14 : <CFString 0x7054370 [0x1175400]>{contents = "email"} = <CFString 0x5c7d2c0 [0x1175400]>{contents = "[email protected]"}
15 : <CFString 0x7059ba0 [0x1175400]>{contents = "BUID"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
16 : <CFString 0x7058120 [0x1175400]>{contents = "1"} = <CFString 0x5c7cf20 [0x1175400]>{contents = "Zary Joon"}
19 : <CFString 0x7058c40 [0x1175400]>{contents = "2"} = <CFString 0x7063630 [0x1175400]>{contents = "Joon"}
22 : <CFString 0x7059b60 [0x1175400]>{contents = "3"} = <CFString 0x5c7d2a0 [0x1175400]>{contents = "Zary"}
23 : <CFString 0x7059bc0 [0x1175400]>{contents = "Department"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
25 : <CFString 0x7059960 [0x1175400]>{contents = "4"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"
26 : <CFString 0x7058770 [0x1175400]>{contents = "LastName"} = <CFString 0x7063630 [0x1175400]>{contents = "Joon"}
28 : <CFString 0x70527b0 [0x1175400]>{contents = "5"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
30 : <CFString 0x7058750 [0x1175400]>{contents = "FullName"} = <CFString 0x5c7cf20 [0x1175400]>{contents = "Zary Joon"}
31 : <CFString 0x70527c0 [0x1175400]>{contents = "6"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
34 : <CFString 0x70527f0 [0x1175400]>{contents = "7"} = <CFString 0x5c7d2c0 [0x1175400]>{contents = "[email protected]"}
36 : <CFString 0x70543a0 [0x1175400]>{contents = "EmployeeId"} = <CFString 0x5c7c100 [0x1175400]>{contents = "J"}
37 : <CFString 0x70563a0 [0x1175400]>{contents = "8"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
38 : <CFString 0x70580e0 [0x1175400]>{contents = "Extension"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
40 : <CFString 0x70563c0 [0x1175400]>{contents = "9"} = <CFString 0x7059970 [0x1175400]>{contents = "N/A"}
}
任何人都可以解釋爲什麼它具有複製後的所有附加信息?
我想你可能已經回答了我的一些問題,順便說一下,謝謝了TON。這終於有道理!謝謝一堆 – zach 2012-02-28 03:45:28