1

テーブルがあり、注文に関する情報をユーザーに提供するために、カスタム tableViewCells を入力したいと考えています。問題は、テーブルビューにセルが表示されますが、必要な情報が入力されていないことです。ブレークポイントを挿入すると、何をしてもセルがゼロであることがわかりました。これは私の cellForRowAtIndexPath です:

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

    OrderClass *orderClass = nil;
    if (filteredArray == nil) {
        if (sortedArray.count >0) {
        orderClass = sortedArray[indexPath.row];
        }
    }
    else if (filteredArray != nil) {
        orderClass = filteredArray[indexPath.row];
    }

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm"];
    NSString *orderDate = [dateFormatter stringFromDate:orderClass.orderDate];

    cell.orderTitle.text = [NSString stringWithFormat:@"%@%@ %@",orderClass.companyName,@",", orderDate];
    cell.orderDetail.text = [NSString stringWithFormat:@"%@ %@ %@ %@.", @"order nummer:",orderClass.orderNumber, @"betaling:", orderClass.orderPaymentType];


    if ([orderClass.orderDelivery isEqualToString:@"Bezorgen"]) {
        cell.orderDelivery.text = [NSString stringWithFormat:@"Levering: Bezorgen op %@, %@, %@", orderClass.orderAdress, orderClass.orderAdressZip, orderClass.orderCity];
    }

    if ([orderClass.orderDelivery isEqualToString:@"Afhalen"]) {
        cell.orderDelivery.text = [NSString stringWithFormat:@"Levering: Afhalen op ingestelde datum en tijd."];
    }

    cell.orderIndication.image = nil;
    if ([orderClass.preparing isEqualToString:@"1"]) {
        if ([orderClass.ready isEqualToString:@"1"] ){
            if ([orderClass.delivered isEqualToString:@"1"]){
                cell.orderIndication.image = [UIImage imageNamed:@"order_3.png"];
            }
            else {
                cell.orderIndication.image = [UIImage imageNamed:@"order_2.png"];
            }
        }
        else {
            cell.orderIndication.image = [UIImage imageNamed:@"order_1.png"];
        }
    }
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"orderCellBG.png"]];

    return cell;
}

誰かが私が間違っていることを知っていますか? どんな助けでも大歓迎です。

4

4 に答える 4

0

これを viewDidLoad に追加して、使用するセルを示します。

UINib *const cell = [UINib nibWithNibName:@"nibName" bundle:[NSBundle mainBundle]];
[_tableView registerNib:cell forCellReuseIdentifier:@"orderOverviewCell"];
于 2013-09-12T14:17:03.253 に答える
0

確認すべき点がいくつかあります。ストーリーボードを使用していて、セルが別の Nib ファイルではなく UITableView 内に含まれるプロトタイプ セルである場合は、一意の識別子が正しいことを確認してください。

大文字と小文字の区別とスペルが重要であるため、セルをクリックしたときに、コードとストーリーボードで「orderOverviewCell」に正しく名前を付けていることを確認してください。

OrderOverViewCell *cell = (OrderOverViewCell *)[tableView dequeueReusableCellWithIdentifier: @"orderOverviewCell"];

上記のコードはセルをインスタンス化し、有効なセルを返すため、nil などをチェックする必要はありません。また、アウトレットとして UITableView を持つ ViewController ではなく、 UITableViewController を使用していると仮定しています。

于 2013-09-12T15:06:01.367 に答える
0

カスタム セルを として定義している場合は、適切な識別子 ( )が割り当てられてPrototype Cellいることを確認してください。StoryboardorderOverviewCell

ここに画像の説明を入力

Apple 開発者ドキュメントによると

プロトタイプ セルはストーリーボードで定義されているため、dequeueReusableCellWithIdentifier: メソッドは常に有効なセルを返します。戻り値を nil と照合して手動でセルを作成する必要はありません。

于 2013-09-12T14:19:51.790 に答える