【发布时间】:2011-02-14 14:45:40
【问题描述】:
我有一个包含 NSMutableArrays 的 NSMutableDictionary。字典代表部门,数组代表该部门内的部门。我正在尝试从 NSMutableArray 的内容中填充 UITableView 的单元格。我目前有 UITableView 显示正确数量的部分(部门)和每个部门中正确的单元格数量 [departmentArray 计数];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [divisionArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSArray *temp = [divisionDict objectForKey:[divisionArray objectAtIndex:section]];
return [temp count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *temp = [divisionArray objectAtIndex:section];
if ([temp isEqualToString:@"School of Humanities and Social Sciences"])
{
temp = @"Humanities and Social Sciences";
} else if ([temp isEqualToString:@"School of Science and Mathematics"]) {
temp = @"Science and Mathematics";
} else if ([temp isEqualToString:@"School of Education"]) {
temp = @"Education";
}
return temp;
}
我在 cellForRowAtIndexPath 中尝试了许多不同的方法来显示每个部门的部门名称,但我无法让它工作。我知道我必须获取每个键的数组,然后遍历该数组并获取每个部门的名称,但是在 cellForRowAtIndexPath 中实现它让我感到困惑。
任何帮助将不胜感激!
【问题讨论】:
标签: iphone ios uitableview nsmutablearray nsmutabledictionary