我想改變tableHeader
高度,字體等...heightForHeaderInSection沒有被調用?
我實現UITableViewDelegate
,UITableViewDataSource
並添加heightForHeaderInSection
和viewForHeaderInSection
。但是這兩種方法沒有被調用。其他方法,如numberOfRowsInSection
/cellForRowAtIndexPath
工作正常。我可以看到表,但沒有頭:(
任何想法
這裏是代碼:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.poHeader.itemList count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"numberOfSectionsInTableView");
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
NSLog(@"*******height");
return 44.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSLog(@"***in viewForHeader In section");
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(2, 166, 300.0, 44.0)];
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor blackColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont systemFontOfSize:13];
headerLabel.frame = CGRectMake(2, 166, 300.0, 44.0);
headerLabel.text = @"Part No. Description Ext Cost"; // i.e. array element
[customView addSubview:headerLabel];
return customView;
}
即使調用委託方法,headerLabel也會出現在錯誤的地方(太低)。它的原點應該是0,0而不是2,166,因爲它是customView的子視圖。 – Anna 2012-01-12 23:10:12