0

このようなテーブルビューを実装しようとしていました

コメントを読んでリンクを表示してください <1>

私の実装は次のとおり
です。1.ペン先からセルを作成します!リンクを見るにはコメントを読んでください <2>

  1. テスト目的で、セルの見出し部分をハードコーディングし、残りをこのようなコードで作成します...

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:                (NSIndexPath *)indexPath
    {
        UITableViewCell *myCell = (UITableViewCell*) 
        [self.tableView dequeueReusableCellWithIdentifier:@"CheckedOutOrderTableCell"];
    
        [[NSBundle mainBundle] loadNibNamed:@"CheckedOutOrderTableCell" owner:self options:NULL];
        myCell = nibLoadedTableCell;
    
        UILabel *orderConditionLabel = [[UILabel alloc] initWithFrame:CGRectMake(250, (85+([[bigDictionary objectAtIndex:indexPath.row]count]*35)), 64, 21)];
        [orderConditionLabel setText:@"Delivered"];
        [orderConditionLabel setFont:[UIFont systemFontOfSize:14]];
        orderConditionLabel.textColor = [UIColor darkGrayColor];
        orderConditionLabel.backgroundColor = [UIColor clearColor];
    
        for(NSInteger i=0; i<[[bigDictionary objectAtIndex:indexPath.row]count]; i++)
        {
            UILabel *quantityLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 85+(i*35), 42, 21)];  
            UILabel *foodLabel = [[UILabel alloc] initWithFrame:CGRectMake(85, 85+(i*35), 175, 21)];
            UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(220, 85+(i*35), 60, 21)];
    
            [quantityLabel setFont:[UIFont systemFontOfSize:15]];
            [foodLabel setFont:[UIFont systemFontOfSize:15]];
            [priceLabel setFont:[UIFont systemFontOfSize:15]];
    
            [quantityLabel setText:[NSString stringWithFormat:@"%@",[[[bigDictionary objectAtIndex:indexPath.row]objectAtIndex:i]valueForKey:@"quantity"]]];           
            [foodLabel setText:[NSString stringWithFormat:@"%@",[[[bigDictionary objectAtIndex:indexPath.row]objectAtIndex:i]valueForKey:@"item_name"]]];        
            [priceLabel setText:[NSString stringWithFormat:@"$ %@.00", [[[bigDictionary objectAtIndex:indexPath.row]objectAtIndex:i]valueForKey:@"price"]]];   
    
            [self.view addSubview:quantityLabel];
            [self.view addSubview:foodLabel];
            [self.view addSubview:priceLabel]; 
            quantityLabel = nil;
            foodLabel = nil;
            priceLabel = nil;
        }
        [self.view addSubview:orderConditionLabel];
        orderConditionLabel = nil;
        return myCell;
    }
    
  2. そしてもちろん、heightForRowAtIndexPath: も書き直して、ついにこれを手に入れました...

http://i.stack.imgur.com/cF7Y4.png

  1. すべてが順調に進んでいるように見えます:D すべてのレーベルが動的に作成され、位置が完璧になります...そして、他のレコードを保存しようとしました....クラッシュしました:'(

http://i.stack.imgur.com/RAXMF.png

  1. NSLOGを使用してこれらのセルに入力したデータをチェックします。以下は「bigDictionary」の構造です

    2012-05-17 12:17:50.330 LazBuy[53187:11903] show structure (
            (
                    {
                "item_name" = "\U8292\U679c\U9752\U8336";
                price = 30;
                quantity = 1;
            },
                    {
                "item_name" = "\U6587\U5c71\U6e05\U8336";
                price = 20;
                quantity = 3;
            },
                    {
                "item_name" = "\U8292\U679c\U9752\U8336";
                price = 30;
                quantity = 3;
            }
        ),
            (
                    {
                "item_name" = "\U51cd\U9802\U70cf\U9f8d\U8336";
                price = 15;
                quantity = 3;
            }
        )
    )
    
  2. データは適切に供給されています。何が問題なのかわかりません!

ラベルが適切に更新されなかったのはなぜですか? リリースする必要がありますか? しかし、ARC ではリリース ラインを作成できないため、リリースできません。

4

1 に答える 1

0

ラベルを self.view に追加していますか? 論文はテーブルビューセルにある必要があります。

[self.view addSubview:quantityLabel];
[self.view addSubview:foodLabel];
[self.view addSubview:priceLabel];

[self.view addSubview:orderConditionLabel];

また、あなたの tableviewcell の再利用はこのようになります

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
 static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"TVCell" owner:self options:nil];
        cell = tvCell;
        self.tvCell = nil;
    }

    // Set your labels text

    return cell;
}
于 2012-05-17T04:55:16.093 に答える