Bạn có nghĩa là headerView hoặc phầnHeaderView không? Bạn có thể thêm subviews đến headerView trong phương pháp viewDidLoad
:
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 225)];
label.text = @"BlaBla";
[self.tableHeaderView addSubview:label];
}
Bạn chỉ rõ kích thước và vị trí của các nhãn với các phương pháp initWithFrame
, và thêm các nhãn như subview đến tableHeaderView - bạn có thể làm điều này với nhiều nhãn.
Nếu bạn có nghĩa là sectionHeader bạn phải thực hiện các phương pháp tableView:viewForHeaderInSection:
, nơi bạn có để tạo ra một cái nhìn mới, và thêm subviews khác nhau với nó:
- (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, 40)];
label.text = @"BlaBla";
[view addSubview:label];
[label release];
return [view autorelease];
}
Trong trường hợp này bạn cũng phải thực hiện phương pháp này tableView:heightForHeaderInSection:
phải trả lại chiều cao của chế độ xem mà bạn tạo theo phương pháp trên:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 50.0f;
}
Ý của bạn là gì với chế độ xem tiêu đề? – willcodejavaforfood
tôi đã sử dụng phương pháp "viewForHeaderInSection". – Pugal