tableView标题拒绝多个子视图

时间:2009-05-29 23:44:44

标签: cocoa-touch uitableview uiview

UITableView的tableViewHeader属性是一个UIView,所以我想我可以添加多个子视图。但是,当我为分段控件添加代码时,UILabel在它不绘制之前会有几行。 Rects 不应该相互重叠。

我做错了什么?

- (void)viewDidLoad {
[super viewDidLoad];

CGRect newFrame = CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, 50.0);
UIView *trialHeaderView = [[UIView alloc] initWithFrame:newFrame];
trialHeaderView.backgroundColor = [UIColor clearColor];

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(15.0, 10.0, 75.0, 25.0)] autorelease];
label.font = [UIFont boldSystemFontOfSize:12.0];
label.text = @"TaDa!";
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
[trialHeaderView addSubview:label];
[label release];

CGRect frame = CGRectMake(80, 10, 100, 35);
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithFrame:frame];
[seg insertSegmentWithTitle:@"Start" atIndex:0 animated:NO];
[seg insertSegmentWithTitle:@"End" atIndex:1 animated:NO];
[trialHeaderView addSubview:seg];

[seg release];

self.tableView.tableHeaderView = trialHeaderView;
[trialHeaderView release];

}

1 个答案:

答案 0 :(得分:0)

本来应该更新这个...我已经自动释放并释放了相同的对象。傻乎乎的......