UITableViewCell
滚动表格视图后,自定义单元格的内容(例如UILabel
文本、UIButton
标题)重置为默认值(标签、按钮)。我在单个表格视图中使用自定义单元格的数量。这些是我用来在单个表格视图中生成多个自定义单元格的代码,每个单元格具有不同的标识符和不同的自定义单元格名称。
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = (customCell1 *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) cell = [[customCell1 alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
{
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customCell1" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (customCell1 *)currentObject;
break;
}
}
}
static NSString *CellIdentifier2 = @"cell2";
UITableViewCell *cell2 = (customCell2 *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell2 == nil) cell2 = [[customCell2 alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
{
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customCell2" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell2 = (customCell2 *)currentObject;
break;
}
}
}
cell.label = @"Test";
[cell2.button setTitle:@"Test Button" forState:UIControlStateNormal];
return cell;
return cell2;