0
當我運行我的ios應用程序時,只有第一個單元格顯示在TableView中,然後單擊時顯示第二個單元格。我希望他們都能同時顯示,但我無法弄清楚這種行爲。第二個單元格僅在Tableview中選擇第一個單元格後出現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;
}
任何幫助,將不勝感激!
感謝您的迴應。當我的(cell == nil)條件有這個{[[NSBundle mainBundle] loadNibNamed:@「ProductTableCell」owner:self options:nil]; cell = self.productCell; }它做我描述的行爲。當我把(cell == nil){cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; }該應用程序崩潰。還有什麼建議?再次感謝! – mikez
@Mikez爲什麼應用程序崩潰,錯誤是什麼?我假設ProductTableCell是一個UITableView子類,因此更具體的你必須做[[[ProductTableCell alloc],這可能是它崩潰的原因,因爲它會因dequeu上的ClassCastException而崩潰。用新代碼編輯我的答案。 –
好吧,當我使用這一行cell = [[[ProductTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];它沒有崩潰,但列表完全是空的 – mikez