Estoy tratando de comprender cómo agregar una etiqueta con un UISwitch u otro controlador a un pie de página (o encabezado) en un tableView seccionado. Cualquier ayuda sería muy apreciada. ¡Gracias de antemano!Cómo agrego un UIButton o UISwitch en tableView: viewForFooterInSection
6
A
Respuesta
8
bien, después de buscar y trabajar en ello que he hecho lo siguiente:
// Need to refactor so that the label is Public Sharing and Priviate Sharing and the actions work for each switch
- (UIView *) tableView: (UITableView *) tableView
viewForFooterInSection: (NSInteger) section
{
if (section == 0 || section == 1) {
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
UIView* footerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)] autorelease];
footerView.autoresizesSubviews = YES;
footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
footerView.userInteractionEnabled = YES;
footerView.hidden = NO;
footerView.multipleTouchEnabled = NO;
footerView.opaque = NO;
footerView.contentMode = UIViewContentModeScaleToFill;
// Add the label
UILabel* footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(150.0, -5.0, 120.0, 45.0)];
footerLabel.backgroundColor = [UIColor clearColor];
footerLabel.opaque = NO;
footerLabel.text = @"Sharing";
footerLabel.textColor = [UIColor tableHeaderAndFooterColor];
footerLabel.highlightedTextColor = [UIColor tableHeaderAndFooterColor];
footerLabel.font = [UIFont boldSystemFontOfSize:17];
footerLabel.shadowColor = [UIColor whiteColor];
footerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
[footerView addSubview: footerLabel];
[footerLabel release];
// Add the switch
UISwitch* footerSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(215.0, 5, 80.0, 45.0)];
[footerView addSubview: footerSwitch];
// Return the footerView
return footerView;
}
else return nil;
}
// Need to call to pad the footer height otherwise the footer collapses
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
switch (section) {
case 0:
case 1:
return 40.0;
default:
return 0.0;
}
}
espero que esto es correcto y si esto ayuda a nadie por favor voten esto. ¡Aclamaciones!
0
creo que es necesario para la AutoRelease uiview-
0
he utilizado un código similar a la ... pero añade un NSLog() llamada justo después de la addSubview.
Cuando me desplazo mi tableView ... consigo 100s de mensaje como:
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
¿Eso es normal? Solo quería el botón ONE, en ONE vista, en la parte inferior de mi TableView.
Cuestiones relacionadas
- 1. iPhone UIButton con funcionalidad UISwitch
- 2. ¿Cómo desactivo un UISwitch?
- 3. Creando un UISwitch programáticamente
- 4. Detectando un cambio en UISwitch
- 5. TableView Footer se desplaza con la tabla
- 6. iOS - Cómo configurar un UISwitch programáticamente
- 7. ¿Cómo obtener el valor de un UISwitch?
- 8. ¿Cómo cambiar el tamaño de un UISwitch?
- 9. Cambiar el texto en un UISwitch
- 10. ¿Cómo agrego un reloj o inspecciono en Xcode?
- 11. UIButton: ¿deberíamos lanzar o no?
- 12. UITableViewCells diferentes en un TableView
- 13. cómo actualizar los datos en tableView?
- 14. ¿Cómo personalizar el botón UISwitch en iphone?
- 15. UISwitch en una celda UITableView
- 16. ¿Cómo agrego un wstring?
- 17. ¿Cómo puedo insertar un UISwitch en una UITableView estática?
- 18. ¿Cómo acceder al pie de página o al encabezado de una sección específica en UITableView?
- 19. Color de UISwitch
- 20. Agregue acción personalizada: @selector a UISwitch en TableViewCell
- 21. Haciendo un botón personalizado usando UIView o reemplazando UIButton?
- 22. ¿Cómo agrego un resplandor exterior a un UIImage o UIImageView o UIView
- 23. Javafx: Reordenar una columna en un TableView
- 24. Cambiar etiqueta de UISwitch
- 25. UISwitch con imagen personalizada
- 26. Mostrar y ocultar UITableViewCell con UISwitch bloqueos demasiado rápidos
- 27. ¿cómo agrego un paquete perdido en Eclipse?
- 28. Cómo crear NSIndexPath para TableView
- 29. UISwitch setSelected no funciona?
- 30. Subclase UIButton o heredar de UIControl?