uitableviewcell source number example data ios objective-c cocoa-touch uitableview

ios - source - uitableviewcell swift 3



¿Puedo forzar un UITableView para ocultar el separador entre celdas vacías? (10)

Esta pregunta ya tiene una respuesta aquí:

Cuando se utiliza un UITableView estilo UITableView con un número suficientemente grande de celdas que el UITableView no puede mostrarlas todas sin desplazamiento, no aparecen separadores en el espacio vacío debajo de las celdas. Si tengo solo unas pocas celdas, el espacio vacío debajo de ellos incluye separadores.

¿Hay alguna manera de forzar a un UITableView a eliminar los separadores en el espacio vacío? Si no, tendré que cargar un fondo personalizado con un separador dibujado para cada celda, lo que hará que sea más difícil heredar el comportamiento.

Encontré una pregunta algo similar here , pero no puedo usar un UITableView agrupado en mi implementación.


Para Swift:

override func viewDidLoad() { super.viewDidLoad() tableView.tableFooterView = UIView() // it''s just 1 line, awesome! }


Para iOS 7. * y iOS 6.1

El método más sencillo es establecer la propiedad tableFooterView :

- (void)viewDidLoad { [super viewDidLoad]; // This will remove extra separators from tableview self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; }

Para versiones anteriores

Puede agregar esto a su TableViewController (esto funcionará para cualquier número de secciones):

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { // This will create a "invisible" footer return 0.01f; }

y si no es suficiente , agrega el siguiente código también :

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; // If you are not using ARC: // return [[UIView new] autorelease]; }


Establecer el separatorStyle la tabla en UITableViewCellSeparatorStyleNone (en código o en IB) debería hacer el truco.


Lo siguiente me funcionó muy bien para este problema:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { CGRect frame = [self.view frame]; frame.size.height = frame.size.height - (kTableRowHeight * numberOfRowsInTable); UIView *footerView = [[UIView alloc] initWithFrame:frame]; return footerView; }

Donde kTableRowHeight es el alto de mis celdas de fila y numberOfRowsInTable es el número de filas que tenía en la tabla.

Espero que ayude,

Brenton


Para Swift:

self.tableView.tableFooterView = UIView(frame: CGRectZero)


Puede lograr lo que desea definiendo un pie de página para la vista de tabla. Vea esta respuesta para obtener más detalles: here


Si usas iOS 7 SDK, esto es muy simple.

Solo agrega esta línea en tu método viewDidLoad:

self.yourTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];


Usando el enlace de Daniel, hice una extensión para hacerlo más útil:

//UITableViewController+Ext.m - (void)hideEmptySeparators { UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; v.backgroundColor = [UIColor clearColor]; [self.tableView setTableFooterView:v]; [v release]; }

Después de algunas pruebas, descubrí que el tamaño puede ser 0 y también funciona. Así que no agrega algún tipo de margen al final de la tabla. Así que gracias wkw por este truco. Decidí publicar eso aquí porque no me gusta la redirección.


Versión rápida

El método más sencillo es establecer la propiedad tableFooterView:

override func viewDidLoad() { super.viewDidLoad() // This will remove extra separators from tableview self.tableView.tableFooterView = UIView(frame: CGRectZero) }


Yo uso lo siguiente:

UIView *view = [[UIView alloc] init]; myTableView.tableFooterView = view; [view release];

Haciéndolo en viewDidLoad. Pero puedes configurarlo en cualquier parte.