(转)参考:http://blog.sina.com.cn/s/blog_65cbfb2b0101cd60.html

第一种,

简单的增加UITableViewCell一些小功能

例如在cell上面添加一个UILabel。

直接在UITableViewCell的生成方法中实现,代码如下

- (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *identifier = @"cell";

UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil) {

cell = [[[UITableViewCell  alloc]initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:identifier] autorelease];

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(190, 0, 130, cell.frame.size.height)];

label1.tag = 1;

[cell.contentView addSubview:label3];

[label3 release];

}

UILabel *label3 = (UILabel *)[cell.contentView viewWithTag:1];

label1.text = @"44444";

return cell;

}

第二种,较为正规的写法。

新建一个自定义的继承UITableViewCell的类如NewCell。

在NewCell中增加两个UILabel的属性

代码如下

//NewCell.h

#import

@interface NewCell : UITableViewCell

{

UILabel *_label1;

UILabel *_label2;

}

- (void)setLabel1Text:(NSString *)text1

label2Text:(NSString *)text2;

@end

//NewCell.m

#import "NewCell.h"

@implementation NewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

if (self) {

_label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 160, self.frame.size.height)];

_label1.text = @"111111111";

[self.contentView addSubview:_label1];

_label2 = [[UILabel alloc] initWithFrame:CGRectMake(160, 0, 160, self.frame.size.height)];

_label2.text = @"111111111";

[self.contentView addSubview:_label2];

}

return self;

}

- (void)setLabel1Text:(NSString *)text1

label2Text:(NSString *)text2

{

_label1.text = text1;

_label2.text = text2;

}

- (void)dealloc

{

[_label1 release];

[_label2 release];

[super dealloc];

}

@end

//UITableViewCell的生成方法

- (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *identifier = @"cell";

NewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil) {

cell = [[[NewCell alloc]initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:identifier] autorelease];

}

[cell setLabel1Text:@"222222222" label2Text:@"333333333"];

return cell;

}

[ios]纯代码实现UITableViewCell的自定义扩展的更多相关文章

  1. iOS纯代码工程手动快速适配

    首先说下让自己的程序支持iPhone6和6+,第一种使用官方提供的launch screen.xib,这个直接看官方文档即可,这里不再多述:第二种方法是和之前iPhone5的类似,比较简单,为iPho ...

  2. iOS纯代码手动适配 分类: ios技术 2015-05-04 17:14 239人阅读 评论(0) 收藏

    首先说下让自己的程序支持iPhone6和6+,第一种使用官方提供的launch screen.xib,这个直接看官方文档即可,这里不再多述:第二种方法是和之前iPhone5的类似,比较简单,为iPho ...

  3. ios - 纯代码创建collectionView

    开始考虑好一点点时间,因为一般的都是用xib,或者storyboard来写的.这次用纯代码...废话较多请看 首先把storyboard干掉,工程里面的main干掉 由于干掉了storyboard则启 ...

  4. IOS 纯代码添加 Button Image Label 添加到自定义View中

    @interface ViewController () /**获取.plist数据*/ @property (nonatomic,strong) NSArray *apps; @end @imple ...

  5. Object-C iOS纯代码布局 一堆代码可以放这里!

    前言: 最近写的文章都是创业类,好吧,今天好好写写技术类的文章! 不过分享的不是IOS相关的文章,毕竟这几天在速成IOS,看的是object-c,由于速成的很快,好累! 好在现在基本已经入了点门道了, ...

  6. Objective-C iOS纯代码布局 一堆代码可以放这里!

    前言: 最近写的文章都是创业类,好吧,今天好好写写技术类的文章! 不过分享的不是IOS相关的文章,毕竟这几天在速成IOS,看的是objective-c,由于速成的很快,好累! 好在现在基本已经入了点门 ...

  7. iOS纯代码适配masonry中mas_的问题

    //equalto 和 mas_equalto 是有区别的.但是我们不打算去了解,可以通过添加以下代码来统一. //注意!! 宏定义必须要放在 import 引入头文件之前! //define thi ...

  8. 使用纯代码定义UICollectionView和自定义UICollectionViewCell

    1.自定义UICollectionView 2.实现<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UICollec ...

  9. iOS 纯代码适配iPhone6,6+

    链接地址:http://blog.csdn.net/codywangziham01/article/details/37658399 转自:http://www.maxiaoguo.com/cloth ...

随机推荐

  1. 关于 0xCCCCCCCC

    http://xingyunbaijunwei.blog.163.com/blog/static/76538067201281793111474/ http://stackoverflow.com/q ...

  2. iOS 蓝牙开发之传输图片

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  3. ssh隧道技术

    大家都知道SSH是一种安全的传输协议,用在连接服务器上比较多.不过其实除了这个功能,它的隧道转发功能更是吸引人.下面是个人根据自己的需求以及在网上查找的资料配合自己的实际操作所得到的一些心得. SSH ...

  4. 安装GRID时跑root.sh脚本报错(ORA-27091: unable to queue I/O)

    在安装GRID过程中,运行root.sh脚本时报如下信息: Adding Clusterware entries to upstart CRS-2672: Attempting to start 'o ...

  5. linux:档案权限

    一.例如:-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc 详细: 1.-rw-r--r--:档案类型和权限(总共十个栏位) 1.1:第一个栏位代表 ...

  6. Synchronized及其实现原理

    并发编程中synchronized一直是元老级角色,我们称之为重量级锁.主要用在三个地方: 1.修饰普通方法,锁是当前实例对象. 2.修饰类方法,锁是当前类的Class对象. 3.修饰代码块,锁是sy ...

  7. Eclipse插件CheckStyle的安装和使用

    转载自:http://www.cnblogs.com/lanxuezaipiao/p/3202169.html CheckStyle是SourceForge下的一个项目,提供了一个帮助JAVA开发人员 ...

  8. Java基础(1):Switch语句注意的5个地方

    不得不说的几点小秘密: 1. switch 后面小括号中表达式的值必须是整型或字符型 2. case 后面的值可以是常量数值,如 1.2:也可以是一个常量表达式,如 2+2 :但不能是变量或带有变量的 ...

  9. MyEclipse下如何安装svn插件

    方法一:在线安装 1.打开HELP->MyEclipse Configuration    不过多数情况下再myeclipse实现不了   Center.切换到SoftWare标签页. 2.点击 ...

  10. ini,config文件的读取修改

    修改ini配置文件 // 声明INI文件的写操作函数 WritePrivateProfileString() [System.Runtime.InteropServices.DllImport(&qu ...