我的UITableView显示来自SOAP Web服务的可变数据。最后一行显示总计。如何将TableView中的最后一行仅作为灰色背景?
这就是我所拥有的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"];
}
NSString *basis = [chunks objectAtIndex:indexPath.row];
NSArray *words2 = [basis componentsSeparatedByString:@":"];
for (NSString *word2 in words2) {
[chunks2 addObject:word2];
}
NSString *artikelnaamfull = @" ";
if ([words2 count] > 2) artikelnaamfull = [words2 objectAtIndex:2];
NSString *aantal = @" ";
if ([words2 count] > 2) aantal = [words2 objectAtIndex:6];
NSString *prijsex = @" ";
if ([words2 count] > 2) prijsex = [words2 objectAtIndex:7];
NSString *artikelnaam = [artikelnaamfull stringByReplacingOccurrencesOfString:@"Omschr =" withString:@""];
if ([artikelnaamfull isEqualToString:@" "]) {
artikelnaam = [words2 objectAtIndex:0];
artikelnaam = [artikelnaam stringByReplacingOccurrencesOfString:@"Totalex= " withString:@"Totaal excl. BTW: € "];
artikelnaam = [artikelnaam stringByReplacingOccurrencesOfString:@"Totalin= " withString:@"Totaal incl. BTW: € "];
cell.contentView.backgroundColor = [UIColor grayColor];
cell.textLabel.backgroundColor = [UIColor grayColor];
cell.textLabel.text = artikelnaam;
cell.detailTextLabel.text = @"";
} else {
aantal = [aantal stringByReplacingOccurrencesOfString:@"Aantal=" withString:@""];
prijsex = [prijsex stringByReplacingOccurrencesOfString:@"Exclusief=" withString:@""];
prijsex = [prijsex stringByReplacingOccurrencesOfString:@"," withString:@"."];
double value = [prijsex doubleValue];
int value2 = [aantal doubleValue];
double totaal = value2 * value;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
NSString *totaal2 = [formatter stringFromNumber:[NSNumber numberWithFloat:totaal]];
cell.textLabel.text = artikelnaam;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ verkocht x € %.2f € %@",aantal,value,totaal2];
}
return cell;
}
我必须添加或更改哪些内容?
谢谢!
答案 0 :(得分:3)
在cellForIndexPath
方法中:
if (indexPath.row == [tableview numberOfRowsInSection:indexPath.section] - 1) {
// set some last row background color
} else {
// set background color for every other row
}