In base alla risposta samvermette's, ma modificato per utilizzare direttamente un'immagine di sfondo piuttosto che comporre un'immagine da una sottoclasse UITableViewCell. La risposta di Sam è buona, ma sarà meno performante rispetto alla semplice creazione di un'immagine di sfondo direttamente.
creare una sottoclasse UIView - in questo esempio ho chiamato CustomTiledView - e aggiungere il seguente codice alla classe:
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"tableview_empty_cell_image"];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM (context, 1, -1);
CGContextDrawTiledImage(context,
CGRectMake(0, 0, rect.size.width, image.size.height),
[image CGImage]);
}
Aggiungere il seguente codice al tuo tableviewcontroller:
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section {
// this can be any size, but it should be 1) multiple of the
// background image height so the last empty cell drawn
// is not cut off, 2) tall enough that footer cells
// cover the entire tableview height when the tableview
// is empty, 3) tall enough that pulling up on an empty
// tableview does not reveal the background.
return BACKGROUND_IMAGE_HEIGHT * 9; // create 9 empty cells
}
- (UIView *)tableView:(UITableView *)tableView
viewForFooterInSection:(NSInteger)section {
CustomTiledView *footerView = [[CustomTiledView alloc] init];
return [footerView autorelease];
}
Infine, dovrai impostare il contenuto inferiore della tabella viewview sul valore negativo del valore restituito da -tableView:heightForFooterInsection:
In questo esempio sarà -1*BACKGROUND_IMAGE_HEIGHT*9
. È possibile impostare il contenuto in basso nella finestra di ispezione delle dimensioni di Interface Builder o impostando la proprietà self.tableView.contentInset
da tableviewcontroller.
Cheers!
* * Bump ottenuto una soluzione che funziona? Si prega di condividere qui. Grazie – lostInTransit
Quello che ho fatto fino ad ora è aggiungere una cella 'invisibile' alla fine della vista tabella con una visualizzazione di immagini che mostra l'ombra della fine della vista tabella. Ho impostato lo stile separatore su none. Questo crea un effetto simile ma dovrò modificarlo un po 'di più per essere felice con esso. –