UITableView:特殊的滚动视图,横向固定,可以在纵向上滚动,自动计算contentSize

创建tableView,初始化时指定样式,默认是plain

UITableView *_tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 20, 375, 600) style:UITableViewStylePlain];

与数据源相关的方法都在dataSource的协议方法中

_tableView.dataSource=self;

与ui相关的方法都在delegate的协议方法中

_tableView.delegate=self;

设置每组的数据行数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

显示每行数据时都会调用此方法,设置每行数据的显示样式(单元格内容样式),显示单元格,采用了可重用机制,当向上拖动tableView显示新的数据时,(原来的单元格不可见,将其加入到可重用队列中,)每次显示单元格信息时先从可重用队列中取出可重用的单元格,如果没有再自己创建

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

设置是否自动调整视图位置

self.automaticallyAdjustsScrollViewInsets=NO;

根据标识符在可重用队列中取出单元格

UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:identifier];

设置单元格右侧的箭头样式

cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

UITableViewCellAccessoryDisclosureIndicator;//右箭头

UITableViewCellAccessoryDetailButton;//问号

UITableViewCellAccessoryDetailDisclosureButton;//问号加右箭头

UITableViewCellAccessoryCheckmark;//对号

UITableViewCellAccessoryNone;//空

图片,一般在左侧显示

cell.imageView.image=[UIImage imageNamed:@"0.png"];

详细信息

cell.detailTextLabel.text=@"detail";

设置每行的行高:默认是44

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

当选择某行数据时调用此协议方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

当取消选择某行数据时,

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;

每个UIViewController都有一个editButtonItem属性,当向它发送editButtonItem消息时会自动创建一个名为edit的UIBarButtonItem对象,自动设定目标-action。自动调用setEditing:animated:方法

self.navigationItem.leftBarButtonItem=self.editButtonItem;

单击导航栏上的edit项时执行此协议方法

-(void)setEditing:(BOOL)editing animated:(BOOL)animated;

设置表视图与edit一样是否处于编辑状态

[_tableView setEditing:editing animated:animated];

section是表视图中每组的编号,从0开始,设置每行的数据行数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

设置tableView的分组数

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

//设置每组的标题,section是组的编号

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

//对tableView编辑(删除、插入)的操作

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

1、删除数据源中的数据(删除第indexPath.section组中第indexPath.row行的数据

[_dataArray[indexPath.section] removeObjectAtIndex:indexPath.row];

2、刷新表视图,第1个参数是删除的行的indexPath组数,第2个参数是动画效果样式

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];

刷新所有的数据

[tableView reloadData];

tableView的编辑状态有UITableViewCellEditingStyleDelete, UITableViewCellEditingStyleInsert, UITableViewCellEditingStyleNone

最新文章

  1. 如果asp.net mvc中某个action被执行了两次,请检查是不是以下的原因
  2. Ported my old SPH solver in Unity
  3. C#的变迁史 - C# 1.0篇
  4. Hello 2016
  5. java中的final总结
  6. [转载] ACE 组播校验和出错问题解决
  7. Cognos 增加全局类
  8. Android自定义标题TitleView
  9. 【HDOJ】1053 Entropy
  10. c# 调用EXCEL在VS上能正常运行,部署在IIS上不能实现,在VS中运行页面和发布之后在IIS中运行的区别
  11. C++_关键字
  12. 【示例代码】HTML+JS 画图板源码分享
  13. 个人php开发之工具--listary(一)
  14. 洛谷P3307 [SDOI2013]项链 [polya定理,莫比乌斯反演]
  15. web前端之Javascript---function函数
  16. window7环境下ZooKeeper的安装运行及监控查看
  17. SharePoint Farm 3-Tier拓扑结构的实施解决方案
  18. defer和async的详细区别
  19. php -- 文件上传下载
  20. Flink流处理之迭代案例

热门文章

  1. spring 第一篇(1-1):让java开发变得更简单(上)
  2. 嵌入式开发之赛灵思 xilinx Zynq芯片简介---Zynq-7000 EPP (XC7Z010 and XC7Z020)
  3. 微信小程序 模块化
  4. iOS --有行距的图文混排
  5. 改动MySQL数据库port号 2.0
  6. linux 大量的TIME_WAIT解决办法(转)
  7. 16进制 ,Color,Colour转换
  8. 山石防火墙debug
  9. JavaScript严格模式为何要禁用With语句
  10. QL 获取当前日期,年、月、日、周、时、分、秒