-5
    if ([[[testMenuGroupAry objectAtIndex:0]objectAtIndex:group] isEqualToString:[filteredAry objectAtIndex:objCount]])
    {
        NSLog(@"object count is %d",objCount);
        [groupAry addObject:[itemList objectAtIndex:group]];
    }
}
    [refArray addObject:groupAry];
    [groupAry release];
    [tempDict setObject:[refArray objectAtIndex:objCount] forKey:[filteredAry objectAtIndex:objCount]];

正在将所有数据输入 tempDict,现在我想将 tempDict 传递给 tableview?

4

1 回答 1

2

你可以这样做。这是用字典填充分区表的一种非常通用的方法:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sortedKeys = [self.tempDict.allKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
    [self.tableView reloadData];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.tempDict count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.tempDict[self.sortedKeys[section]] count];
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return self.sortedKeys[section];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text = self.tempDict[self.sortedKeys[indexPath.section]][indexPath.row];
    return cell;
}
于 2013-05-16T19:28:11.943 回答