He intentado un enfoque diferente. Pero no estoy seguro de si siempre funciona. Tenía un UITableView agrupado y necesitaba hacer una vista de encabezado personalizada. Pero como sabe, al implementar el método viewForHeader inSection no podemos determinar los márgenes para nuestra vista creada. Por lo tanto, lo que he hecho es en primer lugar agregar una propiedad CGRect de archivo ViewController .m:
@property(nonatomic)CGRect groupedCellRectangle;
y en UITableViewDelegate:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
static BOOL groupFrameInitialized = NO;
if(!groupFrameInitialized){
groupFrameInitialized = YES;
self.groupedCellRectangle = cell.contentView.frame;
}
}
después de entonces, en mi método viewForHeader insection:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(self.groupedCellRectangle.origin.x, 0, self.groupedCellRectangle.size.width, 28)];
[v setBackgroundColor:[UIColor clearColor]];
UILabel *label = [[UILabel alloc] initWithFrame:v.frame];
label.text = @"KAF";
[v addSubview:label];
return v;
}
el resultado es el que supongo. groupedCellRectangle ha almacenado correctamente el valor de CGRect con margen.
La idea detrás de este enfoque fue UITableView siempre llame al método viewForHeader después de la llamada willDisplay.
Espero que ayude ...
Es la solución No esbozado trabajando para usted? –