0

这是将文本设置到 tablerows 的代码:

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

但我在每一行都有相同的文本。如何解决这个问题?

非常感谢!

4

2 回答 2

1

可能的解决方案之一是:

- (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;
}
于 2013-09-02T19:55:02.730 回答
0

尝试以下方法之一:

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

或者:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];

    if (cell != nil) cell = nil;
    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;
}
于 2013-09-02T18:50:19.367 回答