05-07-2009, 11:10 PM
#1 (permalink )
New Member
Join Date: May 2009
Posts: 2
How do I add a UIButton or UISwitch in tableView:viewForFooterInSection
Hello. I'm trying to understand how to add a label with a UISwitch or other controller to a footer (or header) in a sectioned tableView. Any help would be greatly appreciated. Thank you in advance!
05-08-2009, 01:44 AM
#2 (permalink )
New Member
Join Date: May 2009
Posts: 2
Okay, after hours or research and coding and re-coding I came up with the following:
Code:
// 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)];
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:
return 40.0;
case 1:
return 40.0;
default:
return 0.0;
}
}
08-16-2009, 10:53 PM
#3 (permalink )
Registered Member
Join Date: Aug 2009
Posts: 1
Thanks
Thanks for posting your code.
Steve.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 652
54 members and 598 guests
alksys7 , amatoria , anonymous@ , Balillas , BillSmith , bob8caldwell , BobK , brentmc79 , ChristianK , CHV , crunkstar , darrentousignant , david77 , dcinqc , deepdelver , desk110 , e.desk , e.dsk100 , e.dsk112 , edesk01 , Emeric , ftwhere , garyshaf , gtyt38 , h2h , HookieTookie , ignicolist , iGuessSo , JamesCahall , JasonR , jbro , Jeremy1026 , jessk2herb , Kryckter , listingboat , lukasluk , MarkC , masc2279 , MiniRobinho , moehac , mofu , nobre84 , raheel , ryanduff , shebinc , Speed , strick242 , sunny dee , tester , virvalid , Ziggy
Most users ever online was 965, 06-30-2010 at 04:26 AM.
» Stats
Members: 51,375
Threads: 52,830
Posts: 225,478
Top Poster: BrianSlick (3,576)
Welcome to our newest member, darrentousignant