J'essaie de comprendre comment ajouter une étiquette avec un UISwitch ou un autre contrôleur à un pied de page (ou un en-tête) dans un tableauView sectionné. Toute aide serait grandement appréciée. Merci d'avance!Comment ajouter un UIButton ou UISwitch dans tableView: viewForFooterInSection
6
A
Répondre
8
Bon, après avoir cherché et travailler à ce que je l'ai fait ce qui suit:
// 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;
}
}
J'espère que cela est correct et si cela aide quelqu'un d'autre s'il vous plaît voter cela. À votre santé!
0
je pense que vous devez autorelease uiview-
0
je un code similaire à celui ... mais j'ajouté un appel NSLog() juste après la addSubview.
Quand je défilement mon tableView ... Je reçois 100s de messages comme:
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
> Adding another subview
Est-ce normal? Je voulais seulement ONE bouton, en ONE voir, tout en bas de ma TableView.
Questions connexes
- 1. cacher ou ajouter un UIBarbuttonitem dans tableview
- 2. UIButton ne fonctionne pas dans la cellule tableview
- 3. ajouter un UIView problème précédent tableView
- 4. Comment ajouter un UIButton à une MKAnnotation (MKView)?
- 5. CoreDataBooks Ajouter nouvelle cellule à tableview
- 6. Comment ajouter une vue au-dessus de mes NavigationControllers TableView
- 7. Uiswitch on/off
- 8. Comment ajouter des données à TableView sur iphone?
- 9. UISwitch méthode d'action
- 10. UIButton comme dans UIActionSheet
- 11. Comment remplir simplement un TableView pour iPhone
- 12. Configuration manuelle un état UIButton
- 13. Comment puis-je ajouter un saut de ligne pour le texte d'un UIButton?
- 14. Barre d'onglets sur TableView?
- 15. Comment ajouter une image à droite de lignes dans TableView sur iPhone?
- 16. multiline uibutton
- 17. uibutton title
- 18. Afficher ou masquer un UIButton dans l'application iPhone avec Objective-C
- 19. Comment définir le type UIButton?
- 20. Étirer une image dans Tableview
- 21. Événements Uibutton
- 22. Obtenir tableView: heightForRowAtIndexPath: se produire après tableView: cellForRowAtIndexPath:?
- 23. connecter un UIActivityIndicator à un UIButton
- 24. uibutton + setselected
- 25. Animer des images UIButton
- 26. UIButton déplacer animation problème
- 27. Iphone: TabView + TableView
- 28. Comment cacher le clavier en utilisant TableView dans Iphone?
- 29. Comment empêcher un UiView de glisser sous TableView?
- 30. UIButton sur iPhone - faire trembler ou bouger le bouton