UITableView的组的自定义与cell的重用
来源:互联网 发布:湖南软件职业学院招聘 编辑:程序博客网 时间:2024/06/08 00:59
@property (nonatomic,readonly, copy) NSString *reuseIdentifier;
所以在设置UITableVIewCell时候都要设置每种cell的Identifier标志来取cell,且每次创建的cell 都放放到dequue的数组里来管理cell的重用,
1.判断首先进来的是哪个组,用参数 indexPath.section获取到所取得得数组
2.首先在dequue的数组里用标志来取cell,实现重用 cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
3.如果cell 为空, 则cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"];来创建;
4.然后index.Path.row来自定义cell的大小,以及在cell上加子视图,(子视图要加到cell.content.view上)
5.- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 来设置section的title
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view.
_homeTableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,20, self.view.frame.size.width /3, self.view.frame.size.height)];
_homeTableView.delegate =self;
_homeTableView.dataSource =self;
[_homeTableView setBackgroundColor:[UIColororangeColor]];
_homeTableView.separatorColor = [UIColorpurpleColor];
// _homeTableView.
//
[self.viewaddSubview:_homeTableView];
}
//tabelView DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger num = 0;
if (section == 0) {
num = 1;
}
else if (section ==1) {
num = 4;
}
else if (section ==2) {
num = 2;
}
return num;
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if (indexPath.section ==0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
if (nil == cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell1"];
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(6,6, 35, 35)];
imageView.image = [UIImageimageNamed:@"Dot.png"];
//contentView
[cell.contentView addSubview:imageView];
}
}
else if (indexPath.section ==1) {
cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
if (nil == cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell2"];
}
switch (indexPath.row) {
case 0:
cell.textLabel.text =@"全部";
break;
case 1:
cell.textLabel.text =@"文档";
break;
case 2:
cell.textLabel.text =@"图片";
break;
case 3:
cell.textLabel.text =@"音频";
break;
default:
break;
}
}
else if (indexPath.section ==2) {
cell = [tableView dequeueReusableCellWithIdentifier:@"cell3"];
if (nil == cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell3"];
}
switch (indexPath.row) {
case 0:
cell.textLabel.text =@"本地相册";
break;
case 1:
cell.textLabel.text =@"网盘相册";
break;
default:
break;
}
}
cell.backgroundColor = [UIColorclearColor];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *title = nil;
if (section == 0) {
title = @"SugarPhoto";
}
if (section == 1) {
title = @"我的文件";
}
if (section == 2) {
title = @"文件来源";
}
return title;
}
//uitableView Delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat key;
if (indexPath.section ==0) {
key = 50;
}
if (indexPath.section ==1 || indexPath.section == 2) {
key = 44;
}
return key;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 35;
}
- UITableView的组的自定义与cell的重用
- UITableView cell的重用
- UITableView 的 自定义cell
- UITableView的自定义cell
- ios UITableView中Cell的重用机制
- UITableView中Cell的重用机制
- UITableView和UICollectionView的cell重用问题
- ios UITableView中Cell的重用机制
- UITableView-cell 的重用机制
- MainStoryBoard 中UITableView Cell的重用
- UITableView中cell的重用机制
- 关于UItabView Cell 自定义重用的 代码
- UITableView的两种重用Cell方法的区别
- UITableView中Cell重用机制导致内容出错的解决方法
- IOS笔记二 UITableView的Cell重用机制
- uitableview 两种设置重用cell的方式
- iOS开发-简述UITableView中cell的重用问题
- IOS UITableView中Cell的重用reuse机制分析
- IOS深入学习(9)之Objective-C
- Git:Git起步
- 关于设计模式3
- Adobe Edge 如何制作全背景图
- 字符数组或字符串逆转的几种方法
- UITableView的组的自定义与cell的重用
- MySQL配置文件my.cnf 例子最详细翻译
- java设计模式分类
- MFC之HTTP客户端应用程序
- 程序员面试、算法研究、编程艺术、红黑树、数据挖掘5大系列集锦
- 如何同时支持IOS5和IOS6上的屏幕旋转?
- EOF
- windows窗口的组成
- MongoDB——第一天 基础入门