2010-10-05 24 views
7

Necesito colocar un botón inmediatamente arriba de una UIViewTable dinámicamente poblada. Se siente bien para no llenar la primera celda (fila 0), pero en lugar de utilizar el área de encabezado, por lo que utilizar el método UITableViewDelegate para crear programación un UIView que contiene un UIButton:Agregar un UIButton en el encabezado del encabezado de UITableView

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{   
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 44)] autorelease]; // x,y,width,height 

    UIButton *reportButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    reportButton.frame = CGRectMake(80.0, 0, 160.0, 40.0); // x,y,width,height 
    [reportButton setTitle:@"rep" forState:UIControlStateNormal]; 
    [reportButton addTarget:self 
        action:@selector(buttonPressed:) 
      forControlEvents:UIControlEventTouchDown];   

    [headerView addSubview:reportButton]; 
    return headerView;  
} 

Sin embargo, como se representa a continuación, la el botón no tiene el espacio necesario (esperaba que la altura del encabezado se adhiriera al argumento 44).

¿Qué pasa aquí? Debo añadir que el UITableView se crea en un archivo XIB por separado.

alt text

Respuesta

7

¿implementó - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section?

+2

Lástima que solo puedo recompensar una respuesta. Gracias. – maralbjo

Cuestiones relacionadas