iPhone开发中关于Xib文件创建UITableViewCell方法
2013-07-16 13:40
405 查看
1、cell不做为controller的插口变量
首先创建一个空的xib文件,然后拖拽一个cell放在其上面,记得设置其属性Identifier,假设设置为“mycell”,则我们在代码中请求cell的时候就应该如下写:
NSString *identifier = @"mycell";
UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier: identifier];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:identifier owner:self options:nil] lastObject];
}
return cell;
2、cell做为controller的插口变量
声明的时候应该写
@property (nonnonatomic, assign) IBOutlet UITableViewCell *tvCell;
@synthesize tvCell
创建nib文件的时候要把file owner选择成当前的controller,然后把IBOut连接起来。
cellForRowAtIndexPath函数实现为:
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"TVCell" owner:self options:nil];
cell = tvCell;
self.tvCell = nil;
}
我们可以通过UINib来提高性能
使用UINib类可以大大的提高性能,正常的nib 加载过程包括从硬盘读取nib file,并且实例化对象。但是当我们使用UINib类时,nib 文件只用从硬盘读取一次,读取之后,内容存在内存中。因为其在内存中,创建一序列的对象会花费很少的时间,因为其不再需要访问硬盘。
头文件中:
ApplicationCell *tmpCell;
// referring to our xib-based UITableViewCell ('IndividualSubviewsBasedApplicationCell')
UINib *cellNib;
@property (nonnonatomic, retain) IBOutlet ApplicationCell *tmpCell;
@property (nonnonatomic, retain) UINib *cellNib;
viewDidLoad中:
self.cellNib = [UINib nibWithNibName:@"IndividualSubviewsBasedApplicationCell" bundle:nil];
cellForRowAtIndexPath实现:
static NSString *CellIdentifier = @"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[self.cellNib instantiateWithOwner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;
}
相关文章推荐
- iPhone开发中关于Xib文件创建UITableViewCell方法
- iPhone开发中关于Xib文件创建UITableViewCell方法
- iPhone开发重构:提供辅助创建方法以简化实例创建【转】
- 关于使用Android Studio 开发NDK项目生成.h文件方法
- iphone开发中使用nib(xib)文件的内存管理
- 关于eclipse创建android项目没有自动生成r文件的解决方法
- 三.OC基础--1.NSString的创建和使用,2多文件开发,3类方法,4封装
- 关于用OO开发ALV中半自动创建输出结构的方法
- Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用MainWindow.xib两种实现)
- iPhone开发笔记[15/50]:指定启动的主界面XIB文件,在xcode4.2里可以不指定MainWindow.xib了
- 在iPhone开发中关于子UIViewController和父UIViewController之间相互调用方法的办法
- iPhone开发中关于Nib文件讲解
- 关于“以前的某个程序安装已在安装计算机上创建挂起的文件操作”解决方法
- iOS开发_iphone开发_文件系统NSFileManager_如何创建、重命名和删除文件
- storyboard中用xib文件创建定制的UITableViewCell对象 .
- 使用xib文件创建UITableViewCell
- iPhone开发关于icon和Default及图片处理方法[转]
- iOS开发——UI基础-自定义构造方法,layoutSubviews,Xib文件,利用Xib自定义View
- iPhone开发之字典转模型——利用创建plist文件和懒加载
- iPhone开发-创建、读取、写入文件 今天的东西是如何在iPhoneOS下创建、删除、读取、写入文件 创建与删除: //创建文件管理器 NSFileManager *fileManager =