gpt4 book ai didi

ios - Backcolor 只有最后一行 UITableView

转载 作者:行者123 更新时间:2023-11-28 20:04:42 25 4
gpt4 key购买 nike

我的 UITableView 显示来自 SOAP 网络服务的可变数据。最后一行显示总计。我怎样才能 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;
}

我必须添加或更改什么才能做到这一点?

谢谢!

最佳答案

在您的cellForIndexPath 方法中:

if (indexPath.row == [tableview numberOfRowsInSection:indexPath.section] - 1) {
// set some last row background color
} else {
// set background color for every other row
}

关于ios - Backcolor 只有最后一行 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22465963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com