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.
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];
}
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.
you can implement - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and you can return what ever view you wanted for each header
来源:https://stackoverflow.com/questions/8485536/uilabel-in-header-of-uitableview-in-objective-c