UITableView用途广泛,而且多样化,其中有一些不太常用,用到的话需要去查资料,今天边用边记录下来

*第一发:UITableViewCell 分割线

1. 分割线样式

  [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

2. 分割线长度

  self.tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);

3. 分割线颜色

  self.tableView.separatorColor = [UIColor blueColor];

3. 自定义分割线

1.设置隐藏分割线

  [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

2.在Cell中重写- (void)drawRect:(CGRect)rect方法

  - (void)drawRect:(CGRect)rect

  {

  CGContextRef context = UIGraphicsGetCurrentContext();

  CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);

    CGContextFillRect(context, rect);

   //上分割线,

   CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor);

   CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1));

//下分割线

   CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor);

  CGContextStrokeRect(context, CGRectMake(24, rect.size.height, rect.size.width - 48, 1));

  }

*第二发:UITableViewCell重要的属性

1.是否可以点击

 self.tableView.allowsSelection = NO;

2.点击cell显示样式

 cell.selectionStyle = UITableViewCellSelectionStyleBlue;

3.点击cell不变色

  cell.selectionStyle = UITableViewCellSelectionStyleNone;

4.cell右边图标

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

  另:cell.accessoryType =  UITableViewCellAccessoryDetailDisclosureButton  cell的右侧是个button,通常会自定义button

  同时附上点击触发相应代理方法

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

NSLog(@"%ld", indexPath.row);

}

4.//滚动  弹簧效果

self.tableView.scrollEnabled = NO;

self.tableView.bounces = NO;

5.//不显示没内容的cell

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

*第三发:UITableView常用方法

 1. //cell展示数据,向后缩进

  - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (indexPath.row == 0) {

return 10;

}

return 0;

}

2.//用来指定cell的触发事件

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

//点击第一个cell 没有反应

if (indexPath.row == 0) {

return nil;

}

return indexPath;

}

 

注意点:

  1.当有多个section时,用UITableViewStyleGrouped,因为经常用UITableViewStylePlain,所以上次遇到问题百思不得其解

  2.代理注意不要忘记了,经常出现代理方法不走,记得回头看看哦

  3.UITableView风格两种样式的不同 UITableViewStyleGrouped头视图不会悬浮,会跟着view一起滚动,特别是两个section的间距,第一系统有默认间距,第二需要同时调用设置header和footer的代理间距,且不能设置为0,可以0.1;而UITableViewStylePlain悬浮最上面,多用于通讯录。

//时间有限,用到再写,持续更新中.......

最新文章

  1. org.springframework.context.ApplicationContextAware使用理解
  2. chart.js插件生成折线图时数据普遍较大时Y轴数据不从0开始的解决办法[bubuko.com]
  3. 解决NetBeans编辑器中文乱码问题
  4. php实现木桶排序
  5. [Tools] Eclipse使用小技巧-持续更新
  6. LoadRunner中截取字符串
  7. python编码:gbk编码与解码
  8. 关于Java线程
  9. 打造基于Clang LibTooling的iOS自动打点系统CLAS(三)
  10. 实体处理模块IEntityModule
  11. Linux 默认日志类型
  12. c# 获取端口的连接数,网站的连接数
  13. springboot集成elasticsearch遇到的问题
  14. 【期望dp】绵羊跳弹簧
  15. Java知多少(57)主线程
  16. convert函数语法
  17. codevs 1423 骑士 - Tarjan - 动态规划
  18. 平台+插件软件设计思想及基于COM的原型实现
  19. 5.8 Components — Composing Components(组合组件)
  20. Mysql-多表连接的操作和用法

热门文章

  1. 每日练习level-7
  2. Django---Blog系统开发之注册页面(验证码&ajax发送文件)
  3. Python编程-面向对象和类
  4. blast+简介
  5. redis memcached MongoDB
  6. BZOJ-1396: 识别子串
  7. 【P2107】小Z的AK计划(优先队列+贪心)
  8. sqoop学习3(数据导入乱码问题)
  9. 闲聊SEO
  10. 用外部物理路由器时使用Neutron dhcp-agent提供的metadata服务(by quqi99)