iphone uitableview 设置分区标题(section title)

1,在为uitableview设置分区标题时,需要用到两个方法。如下

#pragma mark setTitle

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

if (section == 0) {

return 50;

}

return 30;

}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

CGRect frameRect = CGRectMake(0, 0, 100, 40);

UILabel *label = [[[UILabel alloc] initWithFrame:frameRect] autorelease];

label.text=@"myTitle";

return label;

    

 

 

其中title若返回label时,一定要制定label的大小,不然显示不出来,因为label默认的大小是0. 

posted on 2011-10-31 10:40  wtq  阅读(7606)  评论(0编辑  收藏  举报