我有一个这种类型的NSDictionary:
" **********" = (
"20110330 7Huge Sandstorm over niger",
"20110330 8Huge Sandstorm over niger",
"20110330 9CHuge Sandstorm over niger",
"20110330 AHuge Sandstorm over niger",
"20110330 B10CHuge Sandstorm over niger",
"20110330 **CHuge Sandstorm over niger",
""
);
" 2012" = (
"20110330 Huge Sandstorm over niger",
""
);
" just for the test" = (
"20110330 AHuge Sandstorm over niger",
"20110330 BHuge Sandstorm over niger",
"20110330 CHuge Sandstorm over niger",
"20110330 1Huge Sandstorm over niger",
"20110330 2Huge Sandstorm over niger",
"20110330 3Huge Sandstorm over niger",
"20110330 4Huge Sandstorm over niger",
"20110330 5CHuge Sandstorm over niger",
"20110330 6Huge Sandstorm over niger",
""
);我想做一个tableView,带有“*,2012,只是为了测试”不同部分的标题。“尼日尔20110330 7雨格沙尘暴”、“尼日尔上空20110330 8雨格沙尘暴”、“尼日尔20110330 9呼热沙尘暴……”每一节。
请帮帮我。
发布于 2012-06-13 15:03:03
假设每个键中的子元素是NSArrays,那么您可以返回字典中的键数作为节数,每个节的标题的实际键,然后对于每个节中的行数,返回数组中在该特定键下的元素数。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [myDictionary count];//returns the number of key/object pairs
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSArray *allKeys = [myDictionary allKeys];
return [allKeys objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *allKeys = [myDictionary allKeys];
NSString *curKey = [allKeys objectAtIndex:section];
NSArray *curArray = [myDictionary objectForKey:curKey];
return [curArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//normal cell acquisition code
NSArray *allKeys = [myDictionary allKeys];
NSString *curKey = [allKeys objectAtIndex:indexPath.section];
NSArray *curArray = [myDictionary objectForKey:curKey];
NSString *curValue = [curArray objectAtIndex:indexPath.row];
//Do something with the string
}https://stackoverflow.com/questions/11017639
复制相似问题