IOS表格视图的制作.docx

UITableView表格视图 知识点大纲 (1) 表格视图简单实用 (2) 单元格具体内容 (3) 单元格复用 知识点详解 (1) 表格视图简单使用 // UITableViewStylePlain 普通类型 (常用显示大量信息) // UITableViewStyleGrouped 分组类型(常用与配置界面, 联系人界面) UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; // UITableViewDataSource控制表格视图的外观, UITableViewDelegate处理表格视图的事件 // tableView数据源在本类本对象中 // UITableViewDataSource // 与数据有关,tableView要显示什么数据 比如有多少行 有多少分区 // 注意:代理方法中,有两个是必须实现的,没有实现,程序在启动后就会崩掉 tableView.dataSource = self; // 表格视图的代理方法 // UITableViewDelegate // 和数据无关的相关信息,侧重于行为 比如每一行有多高 tableView.delegate = self; // 表格视图如何知道该有多少行? - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{…} // 每行应该显示什么数据 // 什么时候调用? 在显示单元格的时候调用 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ } (2) 单元格具体内容 // 注意: ****为必须实现方法 // 1.返回组数 // 2.返回每组的行数 **** // 3.返回每行中显示数据(cell) **** indexPath.section // 哪一组 indexPath.row // 哪一行 /** ? * cell的类型 ? UITableViewCellStyleDefault, ? 默认模式,标题+可选图像 ? UITableViewCellStyleValue1,? ? 标题+可选图像+明细信息(和标题在同一行) ? UITableViewCellStyleValue2,? ? 标题+明细信息 ? UITableViewCellStyleSubtitle ? 标题+可选图像+明细(和标题不在同一行) ? */ UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; ? ? // 标题 ? ? cell.textLabel.text = name; ? ? // 明细信息 (UITableViewCellStyleValue1类型中) ? ? cell.detailTextLabel.text = hero.intro; ? ? // 图像 ? ? cell.imageView.image = [UIImage imageNamed:hero.icon]; // 背景颜色,会影响到未选中表格行的标签背景 cell.backgroundColor = [UIColor redColor]; // 在实际开发中,使用背景视图的情况比较多 // 背景视图,不需要指定大小,cell会根据自身的尺寸,自动填充调整背景视图的显示 UIImage *bgImage = [[UIImage imageNamed:@rr_pub_button_silver] stretchableImageWithLeftCapWidth:8 topCapHeight:8] cell.backgroundView = [[UIImageView alloc] initWithImage:bgImage]; // UIView *backView = [[UIView alloc] init]; // backView.backgroundColor = [UIColor redColor]; //

文档评论(0)

1亿VIP精品文档

相关文档