Objective c 重复自定义UITableViewCell仅绘制最后一个单元格
在我的UITableView中,我有几个自定义单元格,然后一个自定义单元格需要重复10次,每个单元格中的UILabel值不同。在我尝试多次重复使用上一个自定义单元格之前,一切都很好。最后一个单元格绘制正确,但前9个单元格显示为空白,单元格之间没有拆分 这是我的密码:Objective c 重复自定义UITableViewCell仅绘制最后一个单元格,objective-c,ios,uitableview,Objective C,Ios,Uitableview,在我的UITableView中,我有几个自定义单元格,然后一个自定义单元格需要重复10次,每个单元格中的UILabel值不同。在我尝试多次重复使用上一个自定义单元格之前,一切都很好。最后一个单元格绘制正确,但前9个单元格显示为空白,单元格之间没有拆分 这是我的密码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath { static NSS
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = nil;
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
switch (indexPath.row) {
case 0:
cell = nameCell;
break;
case 1:
cell = globalSettingsCell;
break;
case 2:
cell = queueTypeCell;
break;
case 3:
cell = starMinCell;
break;
case 4:
cell = lengthMaxCell;
break;
}
if (indexPath.row > 4) {
cell = genreCell;
genreLabel.text = [genres objectAtIndex:(indexPath.row - 5)];
}
return cell;
}不能将一个单元格(genreCell)同时用于多个索引路径。您只有一个标识符,但有多个不同的单元格?我认为你不知道如何正确地重复使用细胞 试试这样的
static NSString *CellIdentifier_1 = @"Cell_1";
static NSString *CellIdentifier_2 = @"Cell_2";
//...
UITableViewCell *cell = nil;
switch (indexPath.row) {
case 0:
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier_1];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier_1] autorelease];
}
break;
case 1:
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier_2];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier_2] autorelease];
}
break;
}