user1053651
user1053651

Reputation:

UILabel in header of UITableView in objective c

I am making an iPad app where in I have a grouped TableView with headers for the sections.

i want to add four label in header of tableview

text of four label's are "company", "current", "prev close" ,"change"

or

instead of adding four labels in header, i want to add four text "company", "current", "prev close" ,"change"

What should I do?

Please Help and Suggest.

Thanks.

Upvotes: 2

Views: 3204

Answers (3)

Basheer
Basheer

Reputation: 1207

If you want to show the Company, Current, prev next as text in section title, then just append the text in a single string and return this value in the following delegate method.

(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;

Hope this helps.

Upvotes: 2

PgmFreek
PgmFreek

Reputation: 6402

you can implement - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section and you can return what ever view you wanted for each header

Upvotes: 1

Developer
Developer

Reputation: 6465

There is a delegate method of UITableView for custom view of Header

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
     UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,40)];

     UILabel *objLabel = [[UILabel alloc] initWiThFrame:CGRectMake(0,0,320,40)];
     objLabel.text = @"Post";
     [headerView addSubview:objLabel];   //Similarly You can Add any UI Component on header
     [objLabel release];

     return [headerView autorelease];
}

Upvotes: 8

Related Questions