Edit static tableView cell sections - ios

I have a static tableView with some custom cells. What I wan't to do is change the section titles programmatically. As far as I know, because the cells are static, I can't use methods like cellForRowAtIndexPath and so on, so my question is, is it possibly to change them like.
self.tableView.section1.text = #"title1"; // something like this?
I've tried to create an IBOutlet of the section but I get the following error:
Unknown type name 'UITableViewSection': did you mean 'UITableViewStyle?'
What I can do is edit the content of the cells, but not the header.
Thanks!

Use viewForHeaderInSection method.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *label1 = [[UILabel alloc] init];
label1.frame = CGRectMake(0, 0, 190, 20);
label1.textColor = [UIColor blackColor];
// label1.font = [UIFont fontWithName:#"Helvetica Bold" size:16];
[label1 setFont:[UIFont fontWithName:#"Arial-BoldMT" size:14]];
label1.textAlignment = UITextAlignmentCenter;
label1.text =[NSString stringWithFormat:#"Title %d",section];
// If your title are inside an Array then Use Below Code
label1.text =[titleArray objectAtindex:section];
label1.textColor = [UIColor whiteColor];
label1.backgroundColor = [UIColor clearColor];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[view addSubview:label1];
view.backgroundColor = [UIColor orangeColor];
return view;
}
if You want to use titleForHeaderInSection then use below code.
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:#"Title %d",section];
// If your title are inside an Array then Use Below Code
return [titleArray objectAtindex:section];
}

You can use the UITableViewDelegate Protocol method tableview:titleForHeaderInSection:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = #"";
switch (section) {
case 0: sectionTitle = #"Section 1"; break;
case 1: sectionTitle = #"Section 2"; break;
case 2: sectionTitle = #"Section 3"; break;
default:
break;
}
return sectionTitle;
}
Make sure you declare your <UITableViewDelegate> in your .h file:
#interface SettingsViewController : UITableViewController <UITableViewDelegate> {
}

If you need to change the headers when the view is displayed 'live' you can do so like this:
int sectionNumber = 0;
[self.tableView headerViewForSection:sectionNumber].textLabel.text = #"Foo Bar";
But doing so doesn't seem to change the size of the label frame. I just made mine larger in advance. More details here.

Related

Button in tableview footer is not getting called

I have declared UIView and UIButton in the UIView
-(void)viewWillAppear:(BOOL)animated
{
footerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,300)];
UILabel *totallabel = [[UILabel alloc]initWithFrame:CGRectMake(50,5,320,40)];
totallabel.text = #"Grand Total =";
totallabel.font = [UIFont fontWithName:#"Lato-Regular" size:10];
totallabel.font = [UIFont systemFontOfSize:14];
[footerView addSubview:totallabel];
UILabel *lblRs = [[UILabel alloc]initWithFrame:CGRectMake(160,5,320,40)];
lblRs.text = #"Rs.";
lblRs.font = [UIFont fontWithName:#"Lato-Regular" size:10];
lblRs.font = [UIFont systemFontOfSize:14];
[footerView addSubview:lblRs];
totalcostlabel = [[UILabel alloc]initWithFrame:CGRectMake(190,5,320,40)];
totalcostlabel.font = [UIFont fontWithName:#"Lato-Regular" size:10];
totalcostlabel.font = [UIFont systemFontOfSize:14];
[footerView addSubview:totalcostlabel];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
aButton.frame = CGRectMake(70,50,150,40);
aButton.backgroundColor = [UIColor colorWithRed:119.0/225.0 green:49.0/255.0 blue:88.0/255.0 alpha:1.0];
[aButton setTitle:#"Checkout" forState:UIControlStateNormal];
[aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
aButton.titleLabel.font = [UIFont fontWithName:#"Lato-Regular" size:10];
[aButton addTarget:self action:#selector(btnChackOut:) forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:aButton ];
[self.tblView setTableFooterView:footerView];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return footerView;
}
- (void)btnChackOut:(UIButton *)sender {
NSLog(#"btn clicked");
}
When I click the Checkout button which is declared in my footer the click event is not performed and the action method is not getting called
I got the solution and now it has worked.Apply the below code.
in .h
#import "CustomCell.h"
-(IBAction)actionContinue:(id)sender;
#property (strong, nonatomic) IBOutlet UITableView *tblViewCart;
in .m
#synthesize tblViewCart;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
arrayImageCart = [[NSMutableArray alloc]initWithObjects:#"ios7.jpg",#"iphone_6.jpg",nil];
arrayPrice = [[NSMutableArray alloc]initWithObjects:#"Rs 60,000",#"Rs 55,000",nil];
arrayDescription = [[NSMutableArray alloc]initWithObjects:#"Made In China",#"Headquarter is in US",nil];
arrayOtherDetail = [[NSMutableArray alloc]initWithObjects:#"Black Color",#"White Color",nil];
arraySubTotal = [[NSMutableArray alloc]initWithObjects:#"Rs 60,000",#"Rs 55,000",nil];
arrayTotal = [[NSMutableArray alloc]initWithObjects:#"110000",nil];
arrayTotalCharges = [[NSMutableArray alloc]initWithObjects:#"2000",nil];
arrayYouPay = [[NSMutableArray alloc]initWithObjects:#"112000", nil];
self.tblViewCart.separatorColor = [UIColor clearColor];
}
// Button Action
-(IBAction)actionContinue:(id)sender
{
}
#pragma mark - UITableView Delegate Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 203;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section==0)
return arrayPrice.count;
else
return arrayYouPay.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:#"Reuse"];
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:#"CustomCell" owner:self options:nil];
if(indexPath.section==0)
{
cell = [nib objectAtIndex:0];
cell.imageViewCart.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#",[arrayImageCart objectAtIndex:indexPath.row]]];
cell.lblPriceDetails.text = [NSString stringWithFormat:#"%#",[arrayPrice objectAtIndex:indexPath.row]];
cell.lblDescriptionAbtProduct.text = [NSString stringWithFormat:#"%#",[arrayDescription objectAtIndex:indexPath.row]];
cell.labelOtherDetails.text = [NSString stringWithFormat:#"%#",[arrayOtherDetail objectAtIndex:indexPath.row]];
cell.lblSubTotal.text = [NSString stringWithFormat:#"%#",[arraySubTotal objectAtIndex:indexPath.row]];
}
else
{
cell = [nib objectAtIndex:1];
cell.lblTotal.text = [NSString stringWithFormat:#"%#",[arrayTotal objectAtIndex:indexPath.row]];
cell.lblTotalCharges.text = [NSString stringWithFormat:#"%#",[arrayTotalCharges objectAtIndex:indexPath.row]];
cell.lblYouPay.text = [NSString stringWithFormat:#"%#",[arrayYouPay objectAtIndex:indexPath.row]];
}
return cell;
}
Create Custom Cell through NewFile->Source->CocoaTouchClass->Next>SubClassof:UITableViewCell,Class->CustomClass with CheckBox Also Create XIB file(This is for price details).
Then Inside CustomCell.xib file create another UITableViewCell and give name as CustomCell for Total Amount and Pay.
Can't called because you don't set a height for footer, just need set footer height like this:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 300;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *footerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 304, 40)];
footerView.backgroundColor = [UIColor whiteColor];
UIButton *add_member=[UIButton buttonWithType:UIButtonTypeCustom];
add_member.layer.borderWidth = 0.8;
add_member.layer.cornerRadius = 10;
add_member.layer.masksToBounds = YES;
add_member.layer.borderColor =[[UIColor lightGrayColor] CGColor];
add_member.layer.shadowColor = [[UIColor whiteColor] CGColor];
add_member.layer.shadowOffset = CGSizeMake(0.0, 0.0);
add_member.layer.shadowOpacity = 0.0;
[add_member setTitle:#"Add Member" forState:UIControlStateNormal];
add_member.titleLabel.font = [UIFont fontWithName:#"Arial Rounded MT Bold" size:16];
[add_member addTarget:self action:#selector(AddNewMember:) forControlEvents:UIControlEventTouchUpInside];
[add_member setTitleColor:[UIColor colorWithRed:140.0/255.0 green:198.0/255.0 blue:63.0/255.0 alpha:1.0] forState:UIControlStateNormal];//set the color this is may be different for iOS 7
add_member.frame=CGRectMake(10, 5, 284, 30); //set some large width to ur title
[footerView addSubview:add_member];
return footerView;
}
#pragma mark - Add member
-(IBAction)AddNewMember:(id)sender
{
//Some code
}
Make the property for the button and the mention the property name inside action block like this.
-(IBAction)btn_check:(id)sender
{
BOOL buttonstate;//default state is false.
if(!buttonstate)
{
//Declare your action code here.
//Use the button property name here for your action.
}
else
{
//Declare the button release code here ,its not mandatory.
}

Why is my first section header in table not showing?

I can't figure out why the first section header isn't showing. The second and third show fine. I suspect it's because of the search bar.
I've tried offsetting the whole table like in UISearchBar covered by section header but I didn't notice it offset.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)];
// create the label object
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.frame = CGRectMake(0,0,self.view.frame.size.width,60);
UIColor* mainColor = [UIColor colorWithRed:47.0/255 green:168.0/255 blue:228.0/255 alpha:1.0f];
headerLabel.backgroundColor = mainColor;
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.textAlignment = UITextAlignmentCenter;
if(section == 0)
headerLabel.text = #"Friends";
if(section == 1)
headerLabel.text = #"Second Section Header";
if(section == 2)
headerLabel.text = #"Third Section Header";
headerLabel.textColor = [UIColor whiteColor];
[customView addSubview:headerLabel];
return customView;
}
- (void) hideSearchBar
{
self.feedTableView.contentOffset = CGPointMake( 0, self.searchBar.frame.size.height );
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//Number of rows it should expect should be based on the section
NSDictionary *dictionary = [_imageDataArray objectAtIndex:section];
NSArray *array = [dictionary objectForKey:#"data"];
return [array count];
}
It wasn't showing because i hadn't implemented heightForHeaderInSection
More details here:
in iOS 7 viewForHeaderInSection section is starting from 1 not from 0
You got a bug in your code. Your header is there but it is setting at a y = -60 with a height of 60.
Replace :
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)];
with This
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,300,60)];
Here is the screen shot here
Hope that helps.
In my case I needed to explicitly assign delegates in code, even though delegates were already connected in the XIB file.
tableView.delegate = self
tableView.dataSource = self

How to change font style and background color in titleForHeaderInSection method

after long reading and checking code, I am proud to have a custom table view with sections and section titles, all populated from core data objects. Now I would need to customize the section title and background color. I have seen it done but in a viewForHeaderInSection method. Is is not possible inside my titleForHeaderInSection method?
Here you have my method:
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
id <NSFetchedResultsSectionInfo> theSection = [[self.fetchedResultsController sections]objectAtIndex:section];
NSString *sectionname = [theSection name];
if ([sectionname isEqualToString:#"text 1"]){
return #"Today";
}
else if ([sectionname isEqualToString:#"text 2"]){
return #"Tomorrow";
}
if ([[self.fetchedResultsController sections]count]>0){
id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]objectAtIndex:section];
return [sectionInfo name];
}
else{
return nil;
}
}
simple and optimized
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
// Background color
view.tintColor = [UIColor whiteColor];//[UIColor colorWithRed:77.0/255.0 green:162.0/255.0 blue:217.0/255.0 alpha:1.0];
// Text Color
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
[header.textLabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"tableSection"]]];
}
Here's an example that uses your existing code to set the title text, but lets you use UITableViewHeaderFooterView to adjust the appearance:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *header = #"customHeader";
UITableViewHeaderFooterView *vHeader;
vHeader = [tableView dequeueReusableHeaderFooterViewWithIdentifier:header];
if (!vHeader) {
vHeader = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:header];
vHeader.textLabel.backgroundColor = [UIColor redColor];
}
vHeader.textLabel.text = [self tableView:tableView titleForHeaderInSection:section];
return vHeader;
}
If you want, you can even subclass UITableViewHeaderFooterView just like you'd subclass UITableViewCell to customize the appearance even further.
Swift implementation of #codercat's answer:
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
view.tintColor = UIColor(red: 0.967, green: 0.985, blue: 0.998, alpha: 1) // this example is a light blue, but of course it also works with UIColor.lightGray
var header : UITableViewHeaderFooterView = view as UITableViewHeaderFooterView
header.textLabel.textColor = .red
}
Make a Custom HeaderView by :
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *viewHeader = [UIView.alloc initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 28)];
UILabel *lblTitle =[UILabel.alloc initWithFrame:CGRectMake(6, 3, 136, 21)];
[lblTitle setFont:[UIFont fontWithName:#"HelveticaNeue" size:13]]; //Font style
[lblTitle setTextColor:[UIColor blackColor]];
[lblTitle setTextAlignment:NSTextAlignmentLeft];
[lblTitle setBackgroundColor:[UIColor clearColor]]; //Background
[viewHeader addSubview:lblTitle];
return viewHeader;
}
Give this label any text; I suggest make a seperate NSArray for header titles.
I think that in titleForHeaderInSection you can't change section view properties.
Add to your project viewForHeaderInSection and then add custom custom view with label on it, e.g.
see this hint:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0)] autorelease];
UILabel *label = [[[UILabel alloc] init] autorelease];
label.frame = CGRectMake(0, 0,300, TABLE_HEADER_HEIGHT);
label.backgroundColor = [UIColor clearColor];
label.textColor = TABLE_HEADER_TITLE_COLOR;
label.font = [UIFont fontWithName:FONT_NAME size:14.f];
label.text = [self tableView:tableView titleForHeaderInSection:section];
if (section == 3) {
[headerView setBackgroundColor:[UIColor whiteColor]];
} else {
[headerView setBackgroundColor:[UIColor redColor]];
}
[headerView addSubview:label];
return headerView;
}
You can set title for label according section number.

How to change UITableView Section color and Text color

I have UITableView which populates dates from the plist and Even Section's Title is been populated from plist in UITableView.it gives me the default blue section color and White text color.like this...
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *key = nil;
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView])
{
key = [self.searchResults objectAtIndex:section];
}
else{
key = [self.mySections objectAtIndex:section];
}
// NSString *key = [self.mySections objectAtIndex:section];
return [NSString stringWithFormat:#"%#", key];
}
.
Now I need to change this default text color and Section's color, to do that I am implementing code shown below.But it gives me its own UIView.
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,200,300,244)];
tempView.backgroundColor=[UIColor clearColor];
UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,300,44)];
tempLabel.backgroundColor=[UIColor clearColor];
tempLabel.shadowColor = [UIColor blackColor];
tempLabel.shadowOffset = CGSizeMake(0,2);
tempLabel.textColor = [UIColor redColor]; //here you can change the text color of header.
tempLabel.font = [UIFont fontWithName:#"Helvetica" size:fontSizeForHeaders];
tempLabel.font = [UIFont boldSystemFontOfSize:fontSizeForHeaders];
tempLabel.text=#"Header Text";
[tempView addSubview:tempLabel];
[tempLabel release];
return tempView;
}
To best customize the look of a table section header, you really need to implement two methods: the first one you already have, and it should work, albeit the results won't be very usable.
The second method is the tableView:heightForHeaderInSection:, which tells the UITableView what's the height of the new section, and it can be as simple as this:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 50.0f;
}
EDIT: As per the comment, here's the result of your code and defining the header height:
EDIT 2: If you want red text with a black background, change your code for tableView:viewForHeaderInSection: like this:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,200,300,244)];
tempView.backgroundColor=[UIColor blackColor];
UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,300,44)];
tempLabel.backgroundColor=[UIColor clearColor];
tempLabel.textColor = [UIColor redColor]; //here you can change the text color of header.
tempLabel.font = [UIFont fontWithName:#"Helvetica" size:fontSizeForHeaders];
tempLabel.font = [UIFont boldSystemFontOfSize:fontSizeForHeaders];
tempLabel.text=#"Header Text";
[tempView addSubview:tempLabel];
[tempLabel release];
return tempView;
}
EDIT 3: Ok, so I'll try to merge your code from the first method with the second one. It will look like this:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,200,300,244)];
tempView.backgroundColor=[UIColor blackColor];
UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,300,44)];
tempLabel.backgroundColor=[UIColor clearColor];
tempLabel.textColor = [UIColor redColor]; //here you can change the text color of header.
tempLabel.font = [UIFont fontWithName:#"Helvetica" size:fontSizeForHeaders];
tempLabel.font = [UIFont boldSystemFontOfSize:fontSizeForHeaders];
NSString *key = nil;
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView])
{
key = [self.searchResults objectAtIndex:section];
}
else{
key = [self.mySections objectAtIndex:section];
}
tempLabel.text=[NSString stringWithFormat:#"%#", key];
[tempView addSubview:tempLabel];
[tempLabel release];
return tempView;
}
This should return a table view section header with the proper label and proper look.
EDIT 4: Just a note on how all of this works: if you use tableView:viewForHeaderInSection: whatever code you put in tableView:titleForHeaderInSection: will be ignored. So you need to do the whole setup of the section header, including the proper text in the tableView:viewForHeaderInSection method.

Separate font and color of words in grouped header UItableview

I have three strings that I want to present in header of grouped tableview. Problem is I append this strings in tableView titleForHeaderInSection and I want to present each string in different line with different color and font.
What currently I have is :
What I want is:
I get and append those three string as following
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger) section
{
NSString * presenter = [[self agenda] getBriefingPresenter:section];
NSString * time = [[self agenda] getBriefingTime:section];
NSString * subject = [[[[self agenda] getMeetingBriefings] objectAtIndex:section] objectForKey:#"subject"];
return [NSString stringWithFormat:#"%#\n%# %#", subject, time, presenter ];
}
Method to handle the header font
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(45, 0, 484, 23);
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:#"Century Gothic" size:17];
label.text = sectionTitle;
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 2;
[label sizeToFit];
label.backgroundColor = [UIColor clearColor];
// Create header view and add label as a subview
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 320, 400)];
[view addSubview:label];
return view;
}
So how can I parse this sectionTitle and print as three different labels in three lines?
In (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section, create 3 different labels with specific font and colors. You can't set different fonts/colors on a single UILabel;
So your code updated :
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString * presenter = [[self agenda] getBriefingPresenter:section];
NSString * time = [[self agenda] getBriefingTime:section];
NSString * subject = [[[[self agenda] getMeetingBriefings] objectAtIndex:section] objectForKey:#"subject"];
// Create label with section title
UILabel *presenterLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 0, 484, 23)];
presenterLabel.textColor = presenterColor;
presenterLabel.font = presenterFont;
presenterLabel.text = presenter;
presenterLabel.backgroundColor = [UIColor clearColor];
[presenterLabel sizeToFit];
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, presenterLabel.frame.size.height, 484, 23)];
timeLabel.textColor = timeColor;
timeLabel.font = timeFont;
timeLabel.text = time;
timeLabel.backgroundColor = [UIColor clearColor];
[timeLabel sizeToFit];
UILabel *subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, timeLabel.frame.origin.y + timeLabel.frame.size.height, 484, 23)];
subjectLabel.textColor = subjectColor;
subjectLabel.font = subjectFont;
subjectLabel.text = subject;
subjectLabel.backgroundColor = [UIColor clearColor];
[subjectLabel sizeToFit];
// Create header view and add label as a subview
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
[view addSubview:presenterLabel];
[view addSubview:timeLabel];
[view addSubview:subjectLabel];
return view;
}
and you don't need the - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger) section

Resources