如何用.xib 自定义UITableViewCell
2013-04-11 11:50
274 查看
1、新建一个file,让其继承UITableViewCell,自己定义名字。如:MyTableViewCell
l
![](http://img.my.csdn.net/uploads/201304/11/1365650223_6208.png)
2、新建一个.xib文件,自己定义名字。如:MyTableViewCell.xib
![](http://img.my.csdn.net/uploads/201304/11/1365650356_8067.png)
3、以上两步完成后就可以往.xib托控件了。 首先托一个UITableViewCell,然后托自己需要的控件到这个cell上面,如下图:
![](http://img.my.csdn.net/uploads/201304/11/1365652316_7187.png)
注意:右上角,这里一定要填写在第1步新建File时的那个.h文件的名字“MyTableViewCell”。如图:
![](http://img.my.csdn.net/uploads/201304/11/1365652372_1381.png)
4、完成以上三步时,最后在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static
NSString* cellIdentifier =@"Cell";
//向当前的tableView中注册cell信息,才能在cell子类控件上添加需要显示的数据
UINib*
nib = [UINib nibWithNibName:@"MyTableViewCell"bundle:nil];
[tableViewregisterNib:nib
forCellReuseIdentifier:cellIdentifier];
GameAndSoftwareTableCell* cell = (GameAndSoftwareTableCell*)[tableViewdequeueReusableCellWithIdentifier:cellIdentifier];
if (cell ==
nil) {
cell = [[[GameAndSoftwareTableCellalloc]
initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]
autorelease];
}
cell.titleLabel.text =@"Adobe Photoshop Elements 11 Editor";
cell.contentLabel.text =@"Works great with iPhoto when you are ready to go
beyond the basics. Live in the monent knowing that Adobe@ PhotoShop Elements 11 softWare makes it easy to turn your .....";
return cell;
}
l
![](http://img.my.csdn.net/uploads/201304/11/1365650223_6208.png)
2、新建一个.xib文件,自己定义名字。如:MyTableViewCell.xib
![](http://img.my.csdn.net/uploads/201304/11/1365650356_8067.png)
3、以上两步完成后就可以往.xib托控件了。 首先托一个UITableViewCell,然后托自己需要的控件到这个cell上面,如下图:
![](http://img.my.csdn.net/uploads/201304/11/1365652316_7187.png)
注意:右上角,这里一定要填写在第1步新建File时的那个.h文件的名字“MyTableViewCell”。如图:
![](http://img.my.csdn.net/uploads/201304/11/1365652372_1381.png)
4、完成以上三步时,最后在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static
NSString* cellIdentifier =@"Cell";
//向当前的tableView中注册cell信息,才能在cell子类控件上添加需要显示的数据
UINib*
nib = [UINib nibWithNibName:@"MyTableViewCell"bundle:nil];
[tableViewregisterNib:nib
forCellReuseIdentifier:cellIdentifier];
GameAndSoftwareTableCell* cell = (GameAndSoftwareTableCell*)[tableViewdequeueReusableCellWithIdentifier:cellIdentifier];
if (cell ==
nil) {
cell = [[[GameAndSoftwareTableCellalloc]
initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]
autorelease];
}
cell.titleLabel.text =@"Adobe Photoshop Elements 11 Editor";
cell.contentLabel.text =@"Works great with iPhoto when you are ready to go
beyond the basics. Live in the monent knowing that Adobe@ PhotoShop Elements 11 softWare makes it easy to turn your .....";
return cell;
}
相关文章推荐
- 如何使用xib自定义UITableViewCell
- IOS高访新浪微博界面(讲解如何自定义UITableViewCell,处理@#链接 特殊字符)
- 【ios】论自定义的控件如何在xib中使用,自定义控件在xib中的初始化入口函数
- IOS高访新浪微博界面(讲解如何自定义UITableViewCell,处理@#链接 特殊字符)
- iOS 自定义UITableViewCell上添加UIButton按钮如何确定点击了哪一行,代码块实现
- 如何利用TableView显示自定义nib中创建的UITableViewCell或子类?
- 【swift学习笔记】三.使用xib自定义UITableViewCell
- 如何得到自定义UITableViewCell中的按钮所在的cell
- 使用xib自定义UIView和UITableViewCell以方便布局的方法
- 用xib自定义UITableViewCell的注意事项——重用
- 分区有的视图怎么自定义,如何关联xib
- 用xib自定义UITableViewCell的注意事项——重用问题
- IOS高访新浪微博界面(讲解如何自定义UITableViewCell,处理@#链接 特殊字符)
- ios自定义xib的时候,需要如何初始化里面的控件(添加相关的数据到控件)
- 如何在Xib中添加自定义的属性?
- xib 自定义UITableViewCell 重用
- 分区有的视图怎么自定义,如何关联xib
- iOS UI-团购案例(通过xib文件自定义UITableViewCell)
- iOS高访新浪微博界面(讲解如何自定义UITableViewCell,处理@#链接 特殊字符)