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?
答案 0 :(得分: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;
}