2015年3月25号:要求UItableViewControllor中header view 高度随着内容的变化而改变
方法:
1.自定义headerview 添加代理方法
@protocol HYTSelectHeaderViewDelegate <NSObject>
-(void)selectHeaderViewDidDisplayForHeight:(CGFloat)height;
@end
2.headerview实现方法通知代理
-(CGFloat)height {
//...根据自己内容计算高度...
[self didFinishCalculateHeight:height];
return height;
}
-(void)didFinishCalculateHeight:(CGFloat)height {
if ([self.delegate respondsToSelector:@selector(selectHeaderViewDidDisplayForHeight:)]) {
[self.delegate selectHeaderViewDidDisplayForHeight:height];
}
}
3.UItableViewControllor实现代理方法 获得新高度并重新添加
-(void)setupTableHeaderFooterView {
/** footer,去除多余线条 */
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
/** header, */
HYTSelectHeaderView *headerView = [[HYTSelectHeaderView alloc] init];
//...
headerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, headerView.height);
self.tableView.tableHeaderView = headerView;
}
-(void)selectHeaderViewDidDisplayForHeight:(CGFloat)height {
self.headerView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, height);
[self.tableView setTableHeaderView:self.headerView];
}