在使用静态单元格的时候自定义header/footer view
来源:互联网 发布:怎么下载photoshop软件 编辑:程序博客网 时间:2024/06/05 17:43
今天在storyboard上创建静态单元格制作界面的时候遇到了一些小问题,一些注意点记录一下:
1、数据源/代理方法中也需要放回组数/行数才能显示你在sb上自定义的静态单元格。
2、数据源/代理方法中放回的组数/行数不能超过在sb上定义的静态单元格的组数和行数。
3、想要自定义Header/Footer View的话:
直接在sb上设置header/footer view的内容,如下图,如果没有设置的话,代理方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
是不会被调用的。
在这个方法中采用以下方式创建的话,sb中设置的title会直接设置给创建的header view的textLabel,并且用代码重新设置的话不起作用。但是别的属性可以重新设置。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
staticNSString *ID =@"header";
UITableViewHeaderFooterView *header = [tableViewdequeueReusableHeaderFooterViewWithIdentifier:ID];
if (header ==nil) {
header = [[UITableViewHeaderFooterViewalloc]initWithReuseIdentifier:ID];
header.textLabel.text = @"啦啦啦啦啦";//这个设置不起作用
header.detailTextLabel.text = @"细节细节细节细节细节";//这个设置完看起来也有问题
UITableViewHeaderFooterView *header = [tableViewdequeueReusableHeaderFooterViewWithIdentifier:ID];
if (header ==nil) {
header = [[UITableViewHeaderFooterViewalloc]initWithReuseIdentifier:ID];
header.textLabel.text = @"啦啦啦啦啦";//这个设置不起作用
header.detailTextLabel.text = @"细节细节细节细节细节";//这个设置完看起来也有问题
header.backgroundView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"img"]];//可以设置背景图片
}
return header;
}
要自定义header view的话,使用以下方法:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];//这边可以获得在sb中设置的header的内容
if (sectionTitle ==nil) {
returnnil;
}
UIButton *btn = [[UIButtonalloc]init];
[btn setBackgroundImage:[UIImageimageNamed:@"img"]forState:UIControlStateNormal];
[btn setTitle:sectionTitleforState:UIControlStateNormal];
btn.frame =CGRectMake(20,0,302,64);
UIView *view = [[UIViewalloc]init];
[view addSubview:btn];
return view;
returnnil;
}
UIButton *btn = [[UIButtonalloc]init];
[btn setBackgroundImage:[UIImageimageNamed:@"img"]forState:UIControlStateNormal];
[btn setTitle:sectionTitleforState:UIControlStateNormal];
btn.frame =CGRectMake(20,0,302,64);
UIView *view = [[UIViewalloc]init];
[view addSubview:btn];
return view;
}
0 0
- 在使用静态单元格的时候自定义header/footer view
- 自定义tableview Header和Footer的样式
- 自定义UITableView的Header和Footer
- 07-控件UITableViewController的使用:-header & -footer
- Table Header and Footer View
- 同一header和footer使用在多个页面中
- Yii中的layouts使用(header,footer的使用方式)
- 在空的GridView中顯示Header、Footer列@ASP.Net
- 去掉UItableview header(footer)view 黏性(sticky)
- 去掉UItableview header(footer)view黏性(sticky)
- 去掉UItableview header(footer)view黏性(sticky)
- list view header footer设置顺序
- 去掉UItableview header(footer)view黏性
- 使用RecyclerView实现带Header和Footer的GridView
- 导航栏(Header)和(Footer)的使用简介
- RecyclerView的使用(3)之添加Header和Footer
- RecyclerView的使用(3)之添加Header和Footer
- 使用RecyclerView添加Header和Footer的方法
- Agilent GeneSpring GX V11.5_win32_win64扩展生物学分析软件
- ChemOffice Professional v15.0.0 1CD化工软件
- 面试心得
- HTTPS介绍
- 第十一周项目二 储存班长信息的学生类(2)
- 在使用静态单元格的时候自定义header/footer view
- CSI SAP2000 v17.2.0.1140 1CD结构有限元分析
- Oracle查询用户所有表
- js实现时钟
- BestCoder #42题解(hdu 5232 & 5233 & 5234)
- 【BZOJ 1001】【Beijing 2006】狼抓兔子
- 用HttpUrlConnection抓取网页内容
- sl的历史
- Java WebService 实现读写Redis数据库