I am new to iphone development i have created one view controller and i used grouped table view. Now i want to display the header view in my viewcontroller with image and labels. please guide me and help me out in this problem.
Thanks.
I am new to iphone development i have created one view controller and i used grouped table view. Now i want to display the header view in my viewcontroller with image and labels. please guide me and help me out in this problem.
Thanks.
Do you mean a headerView or a sectionHeaderView? You can add subviews to the headerView in the viewDidLoad
method:
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 225)];
label.text = @"BlaBla";
[self.tableHeaderView addSubview:label];
}
You specify size and position of the label with the initWithFrame
method, and add the label as subview to the tableHeaderView - you can do this with multiple labels.
If you mean the sectionHeader you have to implement the tableView:viewForHeaderInSection:
method, where you have to create a new view, and add different subviews to it:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 225)];
label.text = @"BlaBla";
[view addSubview:label];
return [view autorelease];
}
In this case you also have to implement the method tableView:heightForHeaderInSection:
which has to return the height of the view you create in the above method:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 50.0f;
}