三种自定义CELL 的方法
2013-08-14 18:24
411 查看
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
if (self.cellType == kContentCellType) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
label.tag = 101;
label.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:label];
[label release];
// add subviews ....
}
UILabel *label = (UILabel *)[cell.contentView viewWithTag:101];
label.text = _listArray[indexPath.row];
return cell;
}else if (self.cellType == kNibCellType) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
}
UILabel *label = (UILabel *)[cell.contentView viewWithTag:201];
label.text = _listArray[indexPath.row];
UIImageView *imgView = (UIImageView *)[cell.contentView viewWithTag:202];
imgView.backgroundColor = (indexPath.row%2 == 0) ? [UIColor redColor] : [UIColor yellowColor];
return cell;
}else if (self.cellType == kCustomCellType){
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.text = _listArray[indexPath.row];
// NSLog(@"textLabel >>>>: %@", NSStringFromCGRect(cell.textLabel.frame));
return cell;
}else {
return nil;
}
}
{
static NSString *CellIdentifier = @"Cell";
if (self.cellType == kContentCellType) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
label.tag = 101;
label.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:label];
[label release];
// add subviews ....
}
UILabel *label = (UILabel *)[cell.contentView viewWithTag:101];
label.text = _listArray[indexPath.row];
return cell;
}else if (self.cellType == kNibCellType) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = [nibs objectAtIndex:0];
}
UILabel *label = (UILabel *)[cell.contentView viewWithTag:201];
label.text = _listArray[indexPath.row];
UIImageView *imgView = (UIImageView *)[cell.contentView viewWithTag:202];
imgView.backgroundColor = (indexPath.row%2 == 0) ? [UIColor redColor] : [UIColor yellowColor];
return cell;
}else if (self.cellType == kCustomCellType){
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.text = _listArray[indexPath.row];
// NSLog(@"textLabel >>>>: %@", NSStringFromCGRect(cell.textLabel.frame));
return cell;
}else {
return nil;
}
}
相关文章推荐
- 去掉/自定义 UITableViewCell分割线方法
- 自定义UITableviewCell的三种方法
- 方法选择Android从SD卡中选择图片的三种方法及自定义系统选择框标题的方法
- Android中自定义View的研究(三) -- 获得Bitmap的三种方法
- UITableView 自定义cell 方法
- VC 加载自定义形状鼠标的三种常用方法
- iOS之访问自定义cell的textField.text的N种方法
- Hive中添加自定义udf udaf udtf等函数的jar文件的三种方法
- UITableView实现选择框和编辑状态时cell向右移动的自定义方法
- 运用系统自带的一个Cell然后自定义Cell方法
- 自定义Cell上的点击事件两种方法
- 在自定义cell里面实现跳转的方法
- TableView中画Cell的三种方法
- Android自定义View研究(三) -- 获得Bitmap的三种方法
- 史上最全的iOS之访问自定义cell的textField.text的N种方法
- iOS开发总结之自定义非等高cell-xib(方法一)
- AngularJs基础——自定义服务的三种方法以及provider供应商
- UITabBar的三种常用方法(两种自定义)即自动切换tabbar各个子控制器
- 添加UIview自定义的分割线、去掉默认的cell分割线、默认选中某一个(行)cell的方法
- 自定义cell 且加载 xib 做为模型方法