iOS知识学习】_UITableView简介
来源:互联网 发布:手机淘宝看注册时间 编辑:程序博客网 时间:2024/05/29 10:25
一、它是一个非常重要的类来在table中展示数据。
1、是一个一维的表;
2、是UIScrollView的一个子类;
3、表可以是静态的或者动态的;
4、通过dataSource 协议和 delegate协议可以实现很多的个性化定制;
5、即便拥有大量数据也非常有效率。
二、几种UITableView
1、Plain或者Grouped风格
左边是plain风格,就是一行一行的,右边是grouped风格,一块一块的。
这是plain风格的图片
上图是grouped风格
可以看到里面可以设置Table Header Section Header 、Section Footer等属性,
TableHeader、Section Header SectionFooter、Table Footer可以不设置,默认为空;
Section的数值不设置的话默认为1,
2、静态的或者动态的;
3、被分割为一个个section或者不分割
左图是没有section的,默认就是一个section,右图明显可以看出有几块,每一块就是一个section。
三、UITableView协议
一个UITableView需要继承两个协议:delegate 和 dataSource
delegate:控制table如何展示出来;
dataSource:提供在cell里展示的数据;
注:UITableViewController自动设置为UITableView的delegate和dataSource。
1)UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)sender cellForRowAtIndexPath:(NSIndexPath *)indexPath{ }
这是一个静态方法,作用就是展示index在某一行的cell,该方法返回值是UITableViewCell(UIView的一个子类);
大括号里的实现内容如下:
- UITableViewCell *cell;
- cell = [self.tableView dequeueReusableCellWithIdentifier:@“My Table View Cell”];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
- reuseIdentifier:@“My Table View Cell”];
- }
- cell.textLabel.text = [self getMyDataForRow:indexPath.row inSection:indexPath.section];
- return cell;
该协议可以让用户设置该tableView有多少个Section和多少行,Section的默认值为1;
实现函数如下:
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)sender;
- - (NSInteger)tableView:(UITableView *)sender numberOfRowsInSection:(NSInteger)section;
2)UITableViewDelegate
delegate主要是用来控制UITableView是如何显示的,
当tableView的某一行被选中以后,下面的函数将被执行:
- - (void)tableView:(UITableView *)sender didSelectRowAtIndexPath:(NSIndexPath *)path
- {
- // go do something based on information
- // about my data structure corresponding to indexPath.row in indexPath.section
- }
其他delegate的函数大家自己参考代码。
这边就先不写tableView的某一行的移动、编辑、删除等操作了。有机会再写。
- 【iOS知识学习】_UITableView简介
- iOS知识学习】_UITableView简介
- iOS学习4_UITableView的使用
- iOS学习知识小结
- ios 学习补充知识
- IOS 多线程知识学习
- 【iOS知识学习】_iOS FrameWork相关知识
- 【iOS知识学习】_iOS FrameWork相关知识
- ios学习小知识笔记
- 【iOS知识学习】_Mac截屏
- UI基础_UITableView
- 黑马程序员学习笔记IO知识简介
- 【iOS知识学习】_iPhone学习四舍五入函数
- 【iOS知识学习】_iPhone学习访问联系人
- ios学习--正则表达式简介
- 【iOS知识学习】_iOS入门知识学习(一)
- 【iOS知识学习】_iOS入门知识学习(二)
- 【iOS知识学习】_iOS入门知识学习(二)
- mybatis应用实例学习
- comparison between distinct pointer types 'QPushButton*' and 'QAbstractButton*' lacks a cast
- iOS开发:什么是Bonjour
- HDU 3549 Flow Problem (网络流入门+模板详解)
- spring hibernate transaction
- iOS知识学习】_UITableView简介
- 并查集
- 斐波那契数列的各种求法(终于找全了!)
- HDU_2075
- <转载> c和obj-c如何混用
- Unicode汉字拼音首字母Delphi查询函数
- objective-C 中的内存管理解说
- linux使用
- 常用的正则表达式(转)