簡體   English   中英

使用UITableViewCellStyleDefault在iOS 7中未拾取情節提要UITableView中的自定義單元格

[英]Custom Cell in storyboard UITableView not being picked up in ios7 with UITableViewCellStyleDefault

我在情節提要中添加了一個UITableView,然后通過自定義為其添加了一個單元格。 單元格恢復為空白,調試后,我發現創建的單元格不是我的自定義單元格(我給單元格標記為10來進行測試)。

我的代碼如下:

UITableViewCell *cell = nil;

static NSString *cellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier ];
}

Food *curFood = [self.mealFoods objectAtIndex:indexPath.row];

/// Get the labels of cell
UILabel *descLabel = (UILabel *)[cell.contentView viewWithTag:101];
UILabel *quantityLabel = (UILabel *)[cell.contentView viewWithTag:102];

descLabel.text = curFood.Description;
quantityLabel.text = [NSString stringWithFormat:@"%f", curFood.Quantity];

return cell;

在我在ios6中的上一個項目中,上面的方法運行良好,但標簽不在contentview中。 我是上次忘了做某件事還是現在在ios7中需要做點什么才能使它使用我的原型/自定義單元?

micantox的評論是正確的。 我錯過了在情節提要中的自定義單元中設置單元標識符的方法:

小區標識符

在我的情況下,我的標識符只是“ Cell”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM