1.表视图通常⽤用来管理⼀一组具有相同数据结构的数据。
2.UITableView继承⾃自UIScrollView,所以可以滚动
3.表视图的每⼀一条数据都是显⽰示在UITableViewCell对象中
4.表视图可以分区显⽰示数据,每个分区称为⼀一个section,每⼀一⾏行称为 row,编号都是从0开始
表视图的创建
重要属性
1.style样式一共分为两种:plain和group
2.分割线样式:separatorStyle
3.分割线颜色:separaColor
4.行高:rowHeight
我们需要给tableView指定一个数据源,它负责给tableView提供数据(UITableViewDataSource):
需要实现协议中两个必须实现的方法:
1.返回有多少条数据
-(NSInterger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInterger)section;
- 这个方法主要是设置有几个cell
并对cell的属性进行设置
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
UITableViewCell
1.UITableView中每⼀一个单元格,被称为一个cell
(UITableViewCell)。
2.系统预置了4种(枚举)样式的cell。
3.不同样式的cell包含的控件有细微差别。
在这里可以设置以下几种属性:
1.设置图片:imageView
2.设置文本:textField
3.指定选中效果:selectionStyle
4.指定辅助效果样式:accessoryType
重(chong)用机制
1.UITableView靠mutableSet来实现重⽤用功能
2.出屏幕的cell会被添加到mutableSet中,进⼊入屏幕的cell,先从set中 获取,如果获取不到,才创建⼀一个cell。在cell显⽰示之前,给cell赋上相应的内容。
3.cell的reuseIdentifier是重⽤用的关键
重用(NSIndexPath)的属性
NSIndexPath:
1. 行 :row
2. 分区:section
3. +(NSIndexPath *)indexPathForRow: (NSUInteger)row inSection:(NSUInteger)section
分区(section)
1.tableView默认是⼀一个分区,可以设置多个分区
2.tableView的plain、group样式决定分区的样式不同
3.每个分区可以设置区头区尾
三个方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; //分区数
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; //分区头标题
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView; //右侧竖排索引