2011-07-09 17 views
0

iosアプリケーションを実行すると、最初のセルのみがTableViewに表示され、2番目のセルが表示されます。私はそれらを両方同時に表示することを希望しますが、私はこの動作を把握することはできません。ここでTableviewで最初のセルが選択された後にのみ表示される2番目のセルios

は私のビューのコードがロード

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

    static NSString *CellIdentifier = @"ProductCellId"; 

    ProductTableCell *cell = 
     (ProductTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"ProductTableCell" owner:self options:nil]; 
     cell = self.productCell; 
    }  

    Product *product = [products objectAtIndex:indexPath.row]; 
    [cell configureForProduct:product]; 

    return cell; 
} 

すべてのヘルプははるかに高く評価されるだろうやったです!

答えて

0

あなたはインターフェイスビルダーからあなたの細胞をロードしているので、この試してください:あなたはどのようなあなたのための追加的な情報を見つけることができ

static NSString *CellIdentifier = @"ProductTableCell"; 

:へ

static NSString *CellIdentifier = @"ProductCellId"; 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductTableCell"]; 
     if (cell == nil) { 
     // Load the top-level objects from the custom cell XIB. 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ProductTableCell" owner:self options:nil]; 
     // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain). 
     cell = [topLevelObjects objectAtIndex:0]; 
    } 


Product *product = [products objectAtIndex:indexPath.row]; 
[cell configureForProduct:product]; 


    return cell; 
} 

が変更にこれをこの質問でやろうとしている:Load cells from XIB files

+0

お返事ありがとうございます。 my(cell == nil)条件がこの{[[NSBundle mainBundle] loadNibNamed:@ "ProductTableCell" owner:self options:nil]; cell = self.productCell; }それは私が記述した振る舞いをします。私が(cell == nil){cell [= [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; }アプリは単にクラッシュします。それ以上の提案はありますか?再度、感謝します! – mikez

+0

@Mikezなぜアプリケーションがクラッシュするのですか?エラーは何ですか?私はProductTableCellがUITableViewサブクラスだと仮定していますので、[[ProductTableCell alloc]を行う必要があります。つまり、デキューでClassCastExceptionが発生してクラッシュする可能性があります。私の答えを新しいコードで編集しました。 –

+0

さて、私はこのラインセル= [[ProductTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]を使用しました。それはクラッシュしなかったが、リストは完全に空だった – mikez

関連する問題