views:

1301

answers:

2

Guys, I've a question about printing text in header and footer of table view section. I want to show some text in footer of each row, but i'm having problem doing so. When i start next section it start drawing from below of first one. To Get the idea what exactly i need, go to Settings->General->Network

In this screen, we've multiple sections and after first two sections we've footer information.

Please check this on iPhone 3G. ( I'm not sure if this screen is avaiable on other variants of iPhone ).

Thanks for your help!

Let me know if you need any clarification in the description.

+1  A: 

The UITableViewDelegate protocol allows you to return views for the header and footer of a section. Simply implement this method and return a UILabel filled with the text you want to display.

Dave DeLong
Hey DaveThis is not working for me, I've already tried this. I need to show the text for each section but Using - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionand/or- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section text always go at the bottom of all the sections.I've two sections each with two rows. But this does not show text as desired.
iamiPhone
A: 

Here are two functions implementation but it does not display as desired

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (section == 1) { CGRect rect = CGRectMake(10.0f,40.0f,300.0f,250.0f);

    UILabel* label  = [[[UILabel alloc] initWithFrame:rect] autorelease];
    label.backgroundColor   = [UIColor clearColor];
  label.text  = NSLocalizedString(@"MessageHeader","");;
  label.baselineAdjustment= UIBaselineAdjustmentAlignCenters;
  label.lineBreakMode =  UILineBreakModeWordWrap;
  label.textAlignment = UITextAlignmentCenter;
  label.shadowColor = [UIColor whiteColor];
  label.shadowOffset = CGSizeMake(0.0, 1.0);
  label.font  = [UIFont systemFontOfSize:14];
  label.textColor  = [UIColor darkGrayColor];
  label.numberOfLines = 0;


  UIView *view = [[[UIView alloc] initWithFrame:rect] autorelease];

  [view addSubview:label];

  return view;
 }
} 
return nil;

}

  • (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    if (section == 1) { CGRect rect = CGRectMake(10.0f,80.0f,300.0f,250.0f);

                     UILabel* label = [[[UILabel alloc] initWithFrame:rect] autorelease];
                  label.backgroundColor = [UIColor clearColor];
                  label.text     = NSLocalizedString(@"MessageFooter","");
                  label.baselineAdjustment= UIBaselineAdjustmentAlignCenters;
     label.lineBreakMode  =  UILineBreakModeWordWrap;
     label.textAlignment  = UITextAlignmentCenter;
     label.shadowColor  = [UIColor whiteColor];
     label.shadowOffset  = CGSizeMake(0.0, 1.0);
     label.font   = [UIFont systemFontOfSize:14];
     label.textColor   = [UIColor darkGrayColor];
     label.numberOfLines = 0;
     UIView *view = [[[UIView alloc] initWithFrame:rect] autorelease];
     [view addSubview:label];
    
    
    
    return view;
    
    }

    } return nil; }

What's wrong here? Why Header & footer text goes all the way to bottom of all the sections.

iamiPhone