2014-03-17 6 views
0

Мой UITableView отображает переменные данные из веб-службы SOAP. Последняя строка показывает итоговые значения. Как я могу дать только Последняя строка в TableView сером фоне?Backcolor только последняя строка UITableView

Это то, что у меня есть:

- (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

Просто установите ячейки 'backgroundColor' в' Tableview: willDisplayRowAtIndexPath: 'метод. Не забудьте установить цвет фона для ВСЕХ ячеек, чтобы вы не увидели странных результатов по мере прокрутки таблицы. – rmaddy

+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 
} 
+0

См. Мое редактирование. Как это сделать в моем коде? –

+0

Поместите это ANYWHERE в свой код после того, как вы создали экземпляр объекта 'cell'. – nhgrif

+0

Когда я прокручиваю, другие строки также будут иметь фон. Как это исправить? –

Смежные вопросы