现在的位置: 首页 > 综合 > 正文

IOS学习之——表视图1 概述

2016年03月26日 ⁄ 综合 ⁄ 共 2314字 ⁄ 字号 评论关闭

组成:

1 表头+表脚

2 节+节头+节脚

3 单元格

4 其实表视图的组成和一个班差不多:表(班)+节(小组)+单元格(同学)  无论班级还是小组,都不是实体,只有同学是实在的,如下图


相关类

1 UIScrollView——父类

2 协议:数据源+行为协议

3 controller类

4 UItableviewheaderfooterview 

表视图分类

1 普通表视图——用于动态


2 分组表示图——静态


3 索引表视图

4 搜索表示图

单元格的组成和样式 (系统样式)

单元格组成

1 图标——image

cell.imageView.image=[UIImage imageNamed:imagePath];

2 标题——title

cell.textLabel.text=[[dataList objectAtIndex:indexPath.row] objectForKey:@"name"];

3 副标题——subtitle

    cell.detailTextLabel.text=@"这就是副标题";

4 拓展视图——就是后面跟的那个尾巴

    cell.accessoryType=UITableViewCellAccessoryCheckmark;

拓展视图样式

1 翻译:accessory:附件,配件,副的  closure:关闭,终止,结束  indicate  指出 regular :通常的定期的,有规律的  chevron V 形式   track 跟踪,足迹 checkmark:对勾

2 大约有五种:

1 没有样式

2 V字箭头

3 圆圈i

4 圆圈i+V字箭头

5 对勾

3 代码

//    cell.accessoryType=UITableViewCellAccessoryNone;
//    cell.accessoryType=UITableViewCellAccessoryCheckmark;
//    cell.accessoryType=UITableViewCellAccessoryDetailButton;
//    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

4 上图

箭头

圆圈i+箭头

圆圈i

对勾

单元格样式

依次解释一下:

  1. 默认:有图+title  (没有副标题)
  2. 样式1:image+title+subtitle  副标题在后面
  3. 样式2:title+subtitle  副标题在后面 没有图
  4. 副标题:图+title+subtitle   副标题在下面

代码:

//    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
//    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:cellIdentifier];
//    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

效果:

数据源+协议委托

数据源协议:方法:(必须实现)

  1. -(NSInteger)tableView:numberOfRowsInSection:  ——返回某个节的行数
  2. - (UITableViewCell *)tableView:tableView cellForRowAtIndexPath:  给单元格填充数据

数据源协议:方法:(选择实现)

  1. -(NSString* )tableView: titleForHeaderInSection:  返回节头标题
  2. -(NSSting*)tableView: titleForFooterInSection:  返回节尾标题
  3. -(NSInteger)numberOfSectionsInTableView: 有几节?
  4. -(NSArray*)setionIndexTitleForTableView:  表示图索引标题
  5. -(void) tableView: commitEditingStyle: forRowAtIndexPath: 为删除或修改提供数据

UITableViewDelegate 协议方法

  1. -(void)tableView:didSelectRowAtIndexPath:   单元格被点击的时候调用
  2. -(UIView*)tableView: viewForHeaderInSection:  为节头准备自定义视图
  3. -(UIView*)tableView: viewForFooterInSection: 为节脚准备自定义视图
  4. -(void)tableView:didEndDisplayingHeaderView:forSection:  节头消失时候触发
  5. -(void)tableView:didEndDisplayingFooderView:forSection:  节尾消失时候触发

本文地址:http://blog.csdn.net/zhenggaoxing/article/details/43016323
欢迎转载,转载请注明出处

抱歉!评论已关闭.