【发布时间】:2019-11-14 02:13:12
【问题描述】:
我正在创建自己的个人预算应用程序,该应用程序将商店、花费的金额、日期等数据放到表格中。我按strftime %W 对条目进行排序。我按%W排序的数据字典是:
_results =
{
46 = (
{
DATE = "11/13/2019";
ID = 10;
PLACE = Test;
PRICE = "43.23";
},
{
DATE = "11/15/2019";
ID = 11;
PLACE = OneMore;
PRICE = "32.12";
}
);
47 = (
{
DATE = "11/18/2019";
ID = 12;
PLACE = Kroger;
PRICE = "54.32";
}
);
}
我的 UITableView 设置是:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [_resultsTitles count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[_resultsTitles objectAtIndex:section] stringValue];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// return self.arrFoodInfo.count;
NSNumber *sectionTitle = [_resultsTitles objectAtIndex:section];
NSArray *sectionAnimals = [_results objectForKey:sectionTitle];
return [sectionAnimals count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60.0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Dequeue the cell.
static NSString *identifier = @"idCellRecord";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
// Set the loaded data to the appropriate cell labels.
cell.textLabel.text = [NSString stringWithFormat:@"%@ | $%@", [[self.arrFoodInfo objectAtIndex:indexPath.row] valueForKey:@"PLACE"], [[self.arrFoodInfo objectAtIndex:indexPath.row] valueForKey:@"PRICE"]];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Date: %@", [[self.arrFoodInfo objectAtIndex:indexPath.row] valueForKey:@"DATE"]];
return cell;
}
运行我的应用程序时,表头是正确的,但是在下一节中“添加”一个条目时,第一个条目是重复的。
是否有正确的条目按周数分组显示?
【问题讨论】:
标签: ios objective-c uitableview