ios - 每行结果相同

标签 ios objective-c uitableview

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

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

相关文章:

ios - UITextField 的输入 View 未更改

ios - 在 iOS 项目上设置 Google Analytics 时出现 "guard body may not fall through"错误(在 Swift 中)

objective-c - 如何使用另一个类中的变量显示在我的下一个 Storyboard 场景中

ios - CollectionView标题滚动时停止刷新/重新加载数据

ios - 如何访问项目 > build设置 > 其他 Swift 标志中定义的值?

ios - 按创建日期组织 UITableViewCell

ios - 想要使用 gmail api 执行存档功能

ios - 如何传递与 UITapGestureRecognizer 关联的对象

ios - 在 UITableView 中正确显示 JSON 数据

ios - 如何在隐藏 UIView 后重置 tableview 内容高度