UITableView

一. UITableView设置组与组之间的间距

设置组的头高度和尾高度

self.tableView.sectionHeaderHeight= 5;
self.tableView.sectionFooterHeight= 0;

二.UITableView设置背景颜色

在groub(组)类型的tableview,tableView会被盖上一层backgroundView(一条条斜线的View),这时候设置backgroundColor会没用的,只能先清空backgroundView,然后才能设置tableview的背景颜色

默认样式是没有backgroundView的。

self.tableView.backgroundView= nil;

self.tableView.backgroundColor= [UIColorcolorWithRed:230/ 250.0green:230/ 250.0blue:230/ 250.0alpha:1];

三. 设置tableviewcell不让选中

cell.userInteractionEnabled = NO;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

四. UITableView编辑(Editing)模式下:

  • 设置某一行是否编辑代理方法(很实用,工作中遇到的问题,记录一下)
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSIndexPath * indexP =[NSIndexPath indexPathForRow:0 inSection:0];
    if (indexP == indexPath) {
        return NO;
    }
    return YES;
}
  • 默认选中某一行
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionTop];
 [self tableView:tableView didSelectRowAtIndexPath:indexPath];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容