橘黄色区域是创建的tableHeaderView,那2行按钮本来是添加在这个tableHeaderView上的,却显示在了cell上,是什么问题???
下面是代码:
-(CGFloat)initHeadView:(NSMutableArray *)hotArray
{
CGFloat headHeight = 0.0;
//热門搜索
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Width(_searchTableview), 0)];
view.backgroundColor = [UIColor orangeColor];
if ([hotArray count] > 0)
{
UILabel *lab = [[UILabel alloc]initWithFrame:(CGRect){Margin, 0, 100.0, Size.height}];
lab.font = [UIFont systemFontOfSize:14.0];
lab.textAlignment = NSTextAlignmentLeft;
lab.textColor = [UIColor lightGrayColor];
lab.backgroundColor = [UIColor clearColor];
lab.text = @"熱門搜索";
[view addSubview:lab];
headHeight += Height(lab) + ORIGIN(view).y;
// 热门搜索按钮
CGFloat w = Margin;
NSInteger row = 1;
CGFloat y = 0.0;
CGFloat x = 0.0;
for (int i=0; i<[hotArray count]; i++)
{
UIButton *btn = [self createHotButton:hotArray[i]];
x = w;
if(w+Width(btn)+Margin/2 > MaxWidth){
w = Margin;
x = w;
row ++;
if (row > 2) break;// 最多显示2行
}else{
w += Width(btn)+Margin/2;
}
y = ((row>1) ? (BtnHeight + Margin) : (Margin/2)) + ORIGIN(lab).y + Height(lab);
btn.frame = CGRectMake(x, y, Width(btn), BtnHeight);
[view addSubview:btn];
}//for循环结束
CGFloat btnsH = 0.0;
if (row == 1)
btnsH = Margin/2 + BtnHeight;
else
btnsH = BtnHeight*2 + Margin;
headHeight += btnsH;
}
view.frame = CGRectMake(ORIGIN(view).x, ORIGIN(view).y, Width(_searchTableview), headHeight);
_searchTableview.tableHeaderView = view;
return headHeight;
}
Awak. . . . Apakah tujuan mengembalikan ketinggian? Hanya kembali dan letakkan pulangan pandangan pada pengepala
Apabila membuat butang:
btn.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin; //Tambah ini dan OK