-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
}
你好
我在objective c方面非常新手.......................通过这种方法,我们可以获取标题部分的标题。但是如何更改该字符串的颜色呢?我能做到吗........如果有人知道,请告诉我。
问候
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
}
你好
我在objective c方面非常新手.......................通过这种方法,我们可以获取标题部分的标题。但是如何更改该字符串的颜色呢?我能做到吗........如果有人知道,请告诉我。
问候
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:
(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
tableView.bounds.size.width, 22)];
NSString *dateStr = [[self.data allKeys] objectAtIndex:section];
CGFloat labelWidth = tableView.bounds.size.width / 2;
CGFloat padding = 5.0;
UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake
(padding, 0, (labelWidth - padding), 22)];
labelOne.backgroundColor = [UIColor clearColor];
labelOne.textAlignment = UITextAlignmentLeft;
labelOne.text = dateStr;
UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectMake
(labelWidth, 0, (labelWidth - padding), 22)];
labelTwo.backgroundColor = [UIColor clearColor];
labelTwo.textAlignment = UITextAlignmentRight;
labelTwo.text = @"This is Label TWO";
[headerView addSubview:labelOne];
[headerView addSubview:labelTwo];
[labelOne release];
[labelTwo release];
return headerView;
}
注意,你返回的视图不会被UITableView保留(至少在OS 3.1.2中似乎存在这个问题)。这会导致难以找到的崩溃,在执行viewDidLoad之前就发生了。
表格视图并不像你想象的那样按需获取你的视图。它会请求所有视图,然后再次请求所有视图,有时还会请求多次,因此每次请求都生成视图非常低效。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *tempHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,44)];
tempHeaderView.backgroundColor=[UIColor clearColor];
UILabel *tempHeaderLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,320,44)];
tempHeaderLabel.backgroundColor=[UIColor clearColor];
tempHeaderLabel.text=@"HEADER";
[tempHeaderView addSubView: tempHeaderLabel];
return tempHeaderView;
}