这是将文本设置到表格行中的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath

{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault    reuseIdentifier:@"UITableViewCell"];

    }

    NSString *basis = [chunks objectAtIndex:indexPath.row];

    NSLog(@"ONTVANG: %@", basis);

    NSArray *words2 = [basis componentsSeparatedByString:@":"];
    for (NSString *word2 in words2)
        [chunks2 addObject:word2];

        NSLog(@"Artikelnaam: %@", chunks2);

    NSString *artikelnaamfull = [chunks2 objectAtIndex:2];
    NSString *artikelnaam = [artikelnaamfull stringByReplacingOccurrencesOfString:@"Omschr =" withString:@""];

    cell.textLabel.text = artikelnaam;

    return cell;
}


卡盘是:

(
"Expnr=672 :Artnr=LB-151          :Omschr = Bord plat 25 cm               :Datum=2-9-2013 0:00:00:Aantal=1:Exclusief=1,61:Inclusief=1,948100:Loca_id=0490",
"Expnr=672 :Artnr=LZ01-0032       :Omschr = Alu. decoboot H31 cm          :Datum=2-9-2013 0:00:00:Aantal=1:Exclusief=12,36:Inclusief=14,955600:Loca_id=0490",
"Expnr=672 :Artnr=LZ02-0006       :Omschr = Windlicht antwhite L          :Datum=2-9-2013 0:00:00:Aantal=1:Exclusief=24,75:Inclusief=29,947500:Loca_id=0490",
"Expnr=672 :Artnr=LZ02-0012       :Omschr = Windlicht antwhite L          :Datum=2-9-2013 0:00:00:Aantal=1:Exclusief=24,75:Inclusief=29,947500:Loca_id=0490",
"Expnr=672 :Artnr=LZ02-0065       :Omschr = Kastje met 3 hangers          :Datum=2-9-2013 0:00:00:Aantal=1:Exclusief=10,70:Inclusief=12,947000:Loca_id=0490",
"Expnr=672 :Artnr=LZ03-0013       :Omschr = Pot RND 34,5x10 zwart         :Datum=2-9-2013 0:00:00:Aantal=1:Exclusief=12,36:Inclusief=14,955600:Loca_id=0490",
"Expnr=672 :Artnr=ML-658          :Omschr = Schaaltje porselein 102x70 mm :Datum=2-9-2013 0:00:00:Aantal=8:Exclusief=5,92:Inclusief=7,163200:Loca_id=0490",
"Expnr=672 :Artnr=ML-817          :Omschr = Beker 180 cc                  :Datum=2-9-2013 0:00:00:Aantal=10:Exclusief=8,30:Inclusief=10,043000:Loca_id=0490",
"Expnr=672 :Artnr=ML-843          :Omschr = Voorraadpot glas 11x11x15 cm  :Datum=2-9-2013 0:00:00:Aantal=1:Exclusief=2,07:Inclusief=2,504700:Loca_id=0490",
"Expnr=672 :Artnr=ML-846          :Omschr = Theelichthouder 8 cm zilver   :Datum=2-9-2013 0:00:00:Aantal=2:Exclusief=2,48:Inclusief=3,000800:Loca_id=0490",
"Totalex= 209",
"Totalin= 263"




我必须在不同的行上使用不同的“ Omschr”。

但是我每一行都有相同的文字。如何解决?

非常感谢!

最佳答案

可能的解决方案之一是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault    reuseIdentifier:@"UITableViewCell"];
    }

    NSString *basis = [chunks objectAtIndex:indexPath.row];

    // NSLog(@"ONTVANG: %@", basis);

    NSArray *words2 = [basis componentsSeparatedByString:@":"];
    for (NSString *word2 in words2) {
        [chunks2 addObject:word2];
    }

    // NSLog(@"Artikelnaam: %@", chunks2);

    NSString *artikelnaamfull = @"(invalid input)";
    if ([words2 count] > 2) artikelnaamfull = [words2 objectAtIndex:2];
    NSString *artikelnaam = [artikelnaamfull stringByReplacingOccurrencesOfString:@"Omschr =" withString:@""];

    cell.textLabel.text = artikelnaam;
    return cell;
}

关于ios - 每行结果相同,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18579147/

10-12 22:13
查看更多