UITableView常用属性和一些小知识点

33 篇文章 0 订阅
9 篇文章 0 订阅

1.tableView的样式

1.分段显示UITableViewStylePlain 分段显示,当滑动tableView的时候每组的头部会顶在最上方知道该组所有内容消失换成下一组
这里写图片描述
2.分组显示 UITableViewStyleGrouped
这里写图片描述

2.tableView显示每组头部和尾部的文字通过以下两个方法设置,同样tableView的样式不同显示就不同,如上图所示

1.设置每组的标题和段脚

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;   
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

2.设置每组标题和段脚的高度

  tableView.sectionFooterHeight = 100;
  tableView.sectionHeaderHeight = 10;

3.tableViewCell的分割线

1.分割线属性

tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;

2.分割线的颜色

 tableView.separatorColor = [UIColor redColor];

4.在设置tableView的颜色时需要注意要消除cell 的颜色,不然tableView的颜色会被覆盖

5.cell默认情况下是可以选中的通过设置tableView.allowsSelection = NO可以设置不选中

6.刷新tableView

1.刷新所有行的数据
[self.tableView reloadData];特别需要注意的是刷新tableView,tableView会重新创建tableView的内容,不从缓存池中取
2.刷新指定行的数据

  //刷行指定行的数据
    [self.tableView reloadRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>];

7.使tableView滚动到表格的指定一行

   NSIndexPath *path = [NSIndexPath indexPathForRow:5 inSection:1];
    [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    //atScrollPosition 显示滚动这个位置在屏幕上是什么位置
    /*
     UITableViewScrollPositionNone,
     UITableViewScrollPositionTop,//屏幕的顶部
     UITableViewScrollPositionMiddle,//中间
     UITableViewScrollPositionBottom//底部
     */

8.获取段数及行数

NSLog(@"%ld",self.tableView.numberOfSections);
    NSLog(@"%ld",[self.tableView numberOfRowsInSection:1]);

9.获取到被选中的indexPath

 NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

10.条目多选

 tableView.allowsMultipleSelection = YES;

11.设置所有表格行高

 tableView.rowHeight = 100;

12.在tableView的头部或者尾部添加view,footerView宽度是不用设置的

self.tableView.tableFooterView =xxxView;
self.tableView.tableHeaderView =xxxView;

13.增加tableview滚动区域

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, xx, 0); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值