- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell2";
UILabel *titleLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 300, 20)];
[cell.contentView addSubview:titleLabel];
titleLabel.tag = 0011;
}
else
{
titleLabel = (UILabel *)[cell.contentView viewWithTag:0011];
}
// Configure the cell...
NSMutableString *title = [NSMutableString stringWithString:@"Customer: "];
[title appendString:[titles objectAtIndex:indexPath.row]];
titleLabel.text = title.copy;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = UITextAlignmentLeft;
titleLabel.font = [UIFont systemFontOfSize:18.0];
尽管我的单元格已生成,但我的单元格永远不会为零,而我的 titleLabel 从未被分配。我看不出这是怎么可能的。if 状态永远不会为真,这应该是第一次生成的单元格,但是我的单元格是按原样创建的,没有我的 titleLabel