Я пытаюсь поместить ячейку в пространство между каждой ячейкой, которая будет скрыта установкой alpha = 0. В моей таблице ячейки пространства будут для нечетных строк.
Обратите внимание, что фактическая высота ячейки равна 85, но высота скрытой ячейки (т.е. пространство между ячейками) равна 20.
Проблема в том, что высота космической ячейки равна 85, но не 20, я не знаю почему. Возможно, ячейка загружена неправильно.
Cell
вот UITableViewCell
- фактическая ячейка - с идентификатором "Ячейка".
Cell2
- это пространство с идентификатором "Пространство".
Каждый класс выше имеет свой собственный класс UITableViewCell
, и XIB файлы также назначаются каждому из них. Идентификатор также устанавливается в IB для каждого Xib.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier1 = @"Cell";
static NSString *CellIdentifier2 = @"Space";
Cell *cell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if(!cell)
{
NSArray *ar = [[NSBundle mainBundle] loadNibNamed:@"CellView" owner:nil options:nil];
for (id obj in ar)
{
if ([obj isKindOfClass:[Cell class]])
{
cell = (Cell *)obj;
break;
}
}
}
if (indexPath.row % 2 == 1)
{
Cell2 *cell2 = (Cell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (!cell2)
{
NSArray *ar = [[NSBundle mainBundle] loadNibNamed:@"Cell2" owner:nil options:nil];
for(id obj in ar)
{
if([obj isKindOfClass:[Cell2 class]])
{
cell2 = (Cell2 *)obj;
break;
}
}
// Method 1
cell2 = [[Cell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
// Method 2
//cell2 = [[Cell2 alloc] init];
// Method 3
//cell2 = (Cell2 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
[cell2.contentView setAlpha:0];
// prevent selection and other stuff
[cell2 setUserInteractionEnabled:NO];
}
return cell2;
}
else
{
// Configure the actual cell
}
return cell;
}