Pregunta

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{

 if(section != 0) {

  UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
  view.backgroundColor = [UIColor redColor];

  return view;

 } else {
  return tableView.tableHeaderView;
 }

}

Esta es mi implementación de viewForHeaderInSection pero cualquiera que sea el marco que lo hacen siempre me muestra el mismo marco rojo. ¿Ve usted algún problema con mi código?

Imagen:

introducir descripción de la imagen aquí

ACTUALIZACIÓN:

Mhm ahora mi bloque rojo es mayor, pero mi primera tableHeader está ahora de alguna manera oculta. El primero de ellos se llevó a cabo con el titleForHeaderInSection. Pensé que acaba de poner en práctica la altura de la altura tableHeader pero eso no funciona

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
    return 30;
else
    return tableView.tableHeaderView.frame.size.height;
}
¿Fue útil?

Solución

Es necesario poner en práctica este método delegado

    - (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section;

En su caso, sólo tiene que return 30;.


Además, se filtra la view!

Su [view release] sucede después de la return. Pero tan pronto como el return pasa el método se aborta la ejecución y su release nunca es llamado.

Así que usted quiere esto en su lugar

UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];

Y deshacerse del release explícita abajo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top