【iOS系列】- UITableView的使用


UITableView的常用属性

indexpath.row:行

indexpath.section:组

separatorColor:分割线的颜色

separatorStyle:分割线样式

用来自定义头部和尾部自定义view

只需要设置高度,宽度设置无效

tableHeaderView;

tableFooterView;

table中展示的数据是从模型(或者其他来源-数据源)中取得的,因此要更改表格数据,只需要更改数据源中得数据,并刷新表格即可。(不要直接更改tableviewcell中textLabel中得text数据,这样上下拖动tableview还是会显示原来的数据)

1:修改模型数据

2:刷新表格

常用的刷新表格的方法

//删除数据,表格的刷新
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom]; //插入新数据,表格的刷新
[self.tableView insertRowsAtIndexPaths:(NSArray *) withRowAnimation:(UITableViewRowAnimation)] //全局刷新
reloadData;

UITableViewCell的常用属性

accessoryType:cell右边的指示器

accessoryView:可自定义右边的view

backgroundView:自定义背景view

backgroundColor//优先级低于backgroundView

selectedBackgroundView


常用代理代理方法

//一共有多少组数据
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; //每一组有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; //每一行显示什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; //选中某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath //取消选中某一行
(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath //刷新表格
[self.tableView reloadData];
//注意IndexPaths参数是NSIndexPath的数组
[self.tableView reloadRowsAtIndexPaths:(NSArray *) withRowAnimation:(UITableViewRowAnimation)] // 代理方法,实现了这个方法,就会自动实现了滑动删除功能。
/**
* @param editingStyle 编辑样式:添加,删除
* @param indexPath 删除的行号
*/
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//由于tableview还有插入模式,故这里增加判断
if (editingStyle == UITableViewCellEditingStyleDelete) {//删除操作 }
}


注:tableView加载完毕后没有数据,一定要设置相应的代理方法

tableView.delegate = self;

tableView.dataSource = self;


xib封装view

1:新建xib描述view的内部结构

2:新建类,继承自view(也取决于xib的跟对象,比如UITableViewCell),

3:把xib的类型修改为新建类的类型,并把xib内部的空间和类进行连线

4:提供类方法,可以返回自定义的view


/**
* 构造方法,初始化对象时候调用
* 自定义cell的时候,在这个方法中添加需要显示的子控件
*/
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

//延时操作

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

code to be executed after a specified delay

});


作者:Darren

微博:@IT_攻城师

github:@Darren90

博客:http://www.cnblogs.com/fengtengfei/

欢迎您的访问...


最新文章

  1. Youth -Samuel Ullman
  2. 细说ASP.NET Forms身份认证
  3. [WPF系列-高级TemplateBinding vs RelativeSource TemplatedParent]
  4. Could not open Selected VM debug port (8700) (转)
  5. Android-adb指令
  6. AppleScript的字典怎么看怎么用
  7. string.capwords()函数
  8. SQL中ISNULL用法示例
  9. SVN--分支、合并
  10. 面试时,问哪些问题能试出一个 Android 应用开发者真正的水平?【转自知乎】
  11. Flash图表控件FusionCharts如何定制图表中的趋势线和趋势区
  12. ♫【HTML5 敏捷实践】第1章 使用语义化的方式实现
  13. ubuntu14.04 为Firefox安装flash插件
  14. SPSS19.0实战之聚类分析
  15. 获取字符宽度:并非自适应。coretext去计算
  16. 淘宝内部分享:怎么跳出MySQL的10个大坑
  17. 如何选择版本控制系统之二---Git的研发应用场
  18. 向MIP开源项目提交Issues
  19. Web.Config加密与解密
  20. 谈谈asp,php,jsp的优缺点

热门文章

  1. JDBC-Web项目导入mysql驱动包路径-Eclipse &amp; Myeclipse
  2. h5 页面 禁止网页缩放
  3. 我们需要了解的五个ERP趋势
  4. LeetCode刷题笔记-递归-路径总和
  5. 解决safari里面淘宝京东页面无法打开以及打开后乱码的问题!
  6. Java基础学习总结(91)——阿里巴巴Java开发手册公开版
  7. C#窗体学生成绩管理系统
  8. hexo干货系列:(一)hexo+gitHub搭建个人独立博客
  9. 人生第一场CTF的解题报告(部分)
  10. 洛谷P2057 善意的投票