Questo mi sembra un problema facile, ma ho colpito un muro di mattoni di trovare una soluzione e sto sperando che qualcuno qui può aiutare ...1 pixel tra la prima e la seconda cella UITableView raggruppati
I sto facendo un UITableView con UITableViewStyleGrouped, e sto vedendo un piccolo (1 pixel) linea bianca tra la prima e la seconda fila di ogni sezione del mio vista tabella (vedi immagine)
sembra che la ragione per questa linea è che la prima cella in ogni sezione è 1 pixel più alta delle altre. Quando imposto la cella iniziale di ciascun gruppo ad essere alta 29 pixel (gli altri sono 30) il divario scompare e tutto va bene.
Mentre questa soluzione ha esito positivo, preferirei sapere il motivo per cui ciò si verifica, così posso evitare di usare un trucco incasinato.
FYI:
- ho fatto in modo che questo non è un problema con le immagini di sfondo che ho utilizzando - sono tutti 30px alto, e ho sostituito l'immagine in alto con un'immagine centrale con la stessa risultato.
- Ho rimosso tutti i confini tra le cellule modificando separatorStyle = UITableViewCellSeparatorStyleNone
- Questo effetto non avviene sulla UITableViewStylePlain
Qualsiasi aiuto è molto apprezzato.
Grazie
Codice per la configurazione da tavolo:
myTable = [[UITableView alloc] initWithFrame:CGRectMake(TABLE_SHIFT_OFFSET,
DATE_SLIDER_HEIGHT - DATE_SLIDER_SHADOW_HEIGHT,
326,
self.view.frame.size.height - DATE_SLIDER_HEIGHT + DATE_SLIDER_SHADOW_HEIGHT) style:UITableViewStyleGrouped];
myTable.backgroundColor = [UIColor clearColor];
myTable.backgroundView = nil;
myTable.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:myTable];
myTable.dataSource = self;
myTable.delegate = self;
Codice per la configurazione delle cellule:
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// This is a hack to make sure that a white line doesnt appear between the
// first and second rows in the table, which happens for reasons I dont understand
if (indexPath.row == 0) {
return 29;
}
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"satCell"];
if (!cell)
{
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"satCell"];
}
cell.backgroundView = nil;
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
cell.backgroundColor = [UIColor whiteColor];
int numberOfRowsInThisSection = [self tableView:tableView numberOfRowsInSection:indexPath.section];
if (numberOfRowsInThisSection == 1)
{
cell.backingImage = self.singleWhite;
}
else if (indexPath.row == 0)
{
cell.backingImage = self.topWhite;
}
else if (indexPath.row % 2 == 0)
{
// Even row
if (indexPath.row == numberOfRowsInThisSection - 1)
{
// Last row (even)
cell.backingImage = self.botWhite;
}
else
{
// Normal row (even)
cell.backingImage = self.midWhite;
}
}
else if (indexPath.row % 2 == 1)
{
// Odd row
if (indexPath.row == numberOfRowsInThisSection - 1)
{
// Last row (even)
cell.backingImage = self.botDark;
}
else
{
// Normal row (odd)
cell.backingImage = self.midDark;
}
}
// Setup cell text [REMOVED FOR BREVITY]
return cell;
}
Il codice per l'impostazione della protezione immagine entro MyTableViewCell:
- (void)setBackingImage:(UIImage *)backingImage
{
if (self.backingImage != backingImage)
{
_backingImage = nil;
_backingImage = backingImage;
self.backingView.image = backingImage;
}
}
self.backingView è impostato utilizzando il seguente codice:
[[UIImageView alloc] initWithFrame:CGRectMake(7, 0, 307, 30)];
Siamo in grado di vedere qualche codice? Hai qualcosa in corso in heightForRowAtIndexPath :? –
Il codice relativo alla visualizzazione delle celle sarebbe carino. A quale vista nella cella stai aggiungendo viste, la cella stessa, il contentView o lo sfondoView? Stai aggiungendo le tue immagini che hanno un bordo? Ho fatto alcuni test e penso che lo stile separatore non funzioni con le tabelle raggruppate, disegnano sempre il separatore. –
Ho aggiunto tutto il codice che posso pensare che potrebbe influire sulla struttura della tabella. Sarei felice di aggiungere qualsiasi altra cosa se necessario ... PS. L'hack in heightForRowAtIndexPath: è la mia soluzione attuale. Se l'hack viene rimosso, il gap viene visualizzato nuovamente – sleeke