如果整个程序界面都只是使用UITableView来搭建,一般需要如下步骤:

(1)向界面上拖一个UITableView

(2)设置数据源

(3)设置代理

(4)遵守代理协议

 上述过程相对繁琐,为了简化操作,直接使用UITableViewController,但要一定要注意:需要和主控制器类进行关联,还有就是不要把UIViewController当成UITableViewController使用。
 
自定义TableViewCell(在ATDemoCell.m里):
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"cellID";
    ATDemoCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[ATDemoCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:ID];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
      // 在此处定义控件
    }
   return self;
}

在cellForRowAtIndexPath数据源里调用

ATDemoCell *cell = [ATDemoCell cellWithTableView:tableView];

分割线设置

//设置分割线
[tableView setSeparatorInset:UIEdgeInsetsMake(0, -67, 0, 0)];
//分割线颜色
self.tableView.separatorColor = [UIColor redColor]; //隐藏分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//隐藏多余分割线
self.tableView.tableFooterView = [[UIView alloc] init];

取消选中样式

//取消选中样式
cell.selectionStyle = UITableViewCellSeparatorStyleNone;

设置背景色

// 改变整个tableView的颜色
   tableView.backgroundColor = [UIColor greenColor]

// 设置选中的背景色
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundView.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = selectedBackgroundView; // 设置默认的背景色 1
cell.backgroundColor = [UIColor blueColor]; // 设置默认的背景色 2
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor greenColor];
cell.backgroundView = backgroundView;

右边指示器显示,比如箭头、打勾,也可以自定义图片等等

// 显示箭头
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// 自定义显示,如开关Switch
cell.accessoryView = [[UISwitch alloc] init];

设置tableview 不能滚动

 self.tableView.scrollEnabled =NO; 

最新文章

  1. DBobjectsCompareScript(数据库对象比较).sql
  2. C# 一段绘图代码 在form_load事件不能显示图
  3. MySQL复制配置(多主一从)
  4. qt播放器
  5. 相对路径获取项目文件 及报错 No mapping found for HTTP request with URI XXX in DispatcherServlet with name ‘springmvc’解决方法
  6. H5案例学习笔记
  7. HTML元素,属性,基础标签
  8. 用vs2008打开vs2012项目
  9. My97DatePicker的calendar.js的反混淆
  10. Squid代理服务器&&搭建透明代理网关服务器
  11. <转>maven发布第三方jar的一些问题
  12. sparse autoencoder
  13. hdu 4614 Vases and Flowers (二分 线段树)
  14. .net 实战 根据configuration选项生成不同的config文件
  15. JAVA之JDBC的简单使用(Mysql)
  16. SQL两表之间:根据一个表的字段更新另一个表的字段
  17. E. Bear and Drawing
  18. Android四大组件总结
  19. python常用模块之subprocess
  20. java中正则表达式基本用法(转)

热门文章

  1. vue.js学习之 打包为生产环境后,页面为白色
  2. /etc/fstab 文件如何填写(转)
  3. 关于智能指针类型shared_ptr的计数问题
  4. Line belt(三分镶嵌)
  5. 软件功能说明书——Thunder团队
  6. xml解析----java中4中xml解析方法(转载)
  7. OSG学习:移动/缩放/旋转模型
  8. ios::sync_with_stdio(false)提高C++读写速度
  9. 检测固定IP的端口是否开放批出
  10. MAC锁屏不断网(快捷键启用屏保)