IOS UITableView 常见问题总结(-)
2016-06-19 13:52
495 查看
近期的项目,小编经常会遇到关于tableview 的问题,在这里进行一下总结,希望也能帮助其他同学...
1. 在使用tableview时,如果发现tableview的第一个cell上多出一块,想要取消可以尝试下面的方式:
1). 将tableview的样式设置成plain,
2). 如果section有多组,将第一组的header高度设置为0;这样几本就可以解决了
2. 自定义headerInSection的显示样式,代码如下,还有很重要的一点,<TABleView中每组的header和footer时链接在一起的,如果想要内容在各组间居中显示,一定要将其中一个headerview活着footerview隐藏,应该就可以满足需求>
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *customView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,
screenWidth,30)];
UILabel *headerLab = [[UILabelalloc]init];
[customView addSubview:headerLab];
[headerLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(customView.left).offset(12);
make.centerY.mas_equalTo(customView);
}];
if (section ==1) {
headerLab.text =@"高端品牌";
customView.backgroundColor =
UIColorFromRGBA(0xf0f0f0,
1.0);
}else if(section ==2){
headerLab.textColor = [UIColorwhiteColor];
headerLab.text =
@"最新车源";
customView.backgroundColor =
UIColorFromRGBA(0x5ca6e9,
1.0);
}else{
headerLab.text =@"";
}
return customView;
}
3. 实现cell自定义编辑功能
- (NSArray<UITableViewRowAction
*> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath{
UITableViewRowAction *edit = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"编辑"handler:^(UITableViewRowAction
*_Nonnull action,NSIndexPath *
_Nonnull indexPath) {
}];
edit.backgroundColor = [UIColorcolorWithRed:11/256.0green:93/256.0blue:213/256.0alpha:1];
UITableViewRowAction *delete = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"删除"handler:^(UITableViewRowAction
*_Nonnull action,NSIndexPath *
_Nonnull indexPath) {
// 1. 实现点击功能,多为对于数据源的增删改
// 2.刷新表格
[self.tableView reloadData];
}];
delete.backgroundColor = [UIColorcolorWithRed:11/256.0green:93/256.0blue:213/256.0alpha:1];
NSArray *arr =
@[edit,delete];
return arr;
}
1. 在使用tableview时,如果发现tableview的第一个cell上多出一块,想要取消可以尝试下面的方式:
1). 将tableview的样式设置成plain,
2). 如果section有多组,将第一组的header高度设置为0;这样几本就可以解决了
2. 自定义headerInSection的显示样式,代码如下,还有很重要的一点,<TABleView中每组的header和footer时链接在一起的,如果想要内容在各组间居中显示,一定要将其中一个headerview活着footerview隐藏,应该就可以满足需求>
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *customView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,
screenWidth,30)];
UILabel *headerLab = [[UILabelalloc]init];
[customView addSubview:headerLab];
[headerLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(customView.left).offset(12);
make.centerY.mas_equalTo(customView);
}];
if (section ==1) {
headerLab.text =@"高端品牌";
customView.backgroundColor =
UIColorFromRGBA(0xf0f0f0,
1.0);
}else if(section ==2){
headerLab.textColor = [UIColorwhiteColor];
headerLab.text =
@"最新车源";
customView.backgroundColor =
UIColorFromRGBA(0x5ca6e9,
1.0);
}else{
headerLab.text =@"";
}
return customView;
}
3. 实现cell自定义编辑功能
- (NSArray<UITableViewRowAction
*> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath
*)indexPath{
UITableViewRowAction *edit = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"编辑"handler:^(UITableViewRowAction
*_Nonnull action,NSIndexPath *
_Nonnull indexPath) {
}];
edit.backgroundColor = [UIColorcolorWithRed:11/256.0green:93/256.0blue:213/256.0alpha:1];
UITableViewRowAction *delete = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"删除"handler:^(UITableViewRowAction
*_Nonnull action,NSIndexPath *
_Nonnull indexPath) {
// 1. 实现点击功能,多为对于数据源的增删改
// 2.刷新表格
[self.tableView reloadData];
}];
delete.backgroundColor = [UIColorcolorWithRed:11/256.0green:93/256.0blue:213/256.0alpha:1];
NSArray *arr =
@[edit,delete];
return arr;
}
相关文章推荐
- “车城”项目问题总结之UITableView不同样式cell的运用
- build.xml
- thinkjs请求oss报错:RequestTimeTooSkewedError:
- 队列queue
- lucene query
- [LeetCode] Count Numbers with Unique Digits
- JAVA--019 GUI
- UIView 中简单的九宫格
- Arduino 卡片13自制风扇
- Arduino的程序烧录
- 应用服务器性能优化 之 消息队列(MQ:Message Queue)
- UGUI如何判断鼠标是否在UI上
- Arduino 卡片12彩灯调光台
- postgresql----数据库表约束----UNIQUE
- 妙用php中的register_shutdown_function和fastcgi_finish_request
- java基础知识:break语句和continue语句
- iOS-UIStackView浅析
- ajax调后台servlet,把返回json用vue做绑定
- Increasing Triplet Subsequence
- Arduino 卡片11可控舵机