tableView的单元格的定制的方法
来源:互联网 发布:seo数据是什么 编辑:程序博客网 时间:2024/05/16 19:04
1、在 cellForRowAtIndexPath 函数中创建
//定制单元格
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 200, 30)];
nameLabel.tag =12;
然后通过tag的值来获取控件
UILabel *nameLabel =(UILabel *)[cell.contentView viewWithTag:12];
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(5, 30, 68, 68)];
imageview.tag =11;
[self.contentView addSubview:imageview];
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 200, 30)];
nameLabel.tag =12;
[self.contentView addSubview:nameLabel];
UILabel *nickLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 40, 200, 30)];
nickLabel.tag =13;
[self.contentView addSubview:nickLabel];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 75, 200, 30)];
dateLabel.tag =14;
[self.contentView addSubview:dateLabel];
}
return self;
}
static BOOL b=NO;
if (!b) {
UINib *nib = [UINib nibWithNibName:@"Cell" bundle:[NSBundle mainBundle]];
[tableView registerNib:nib forCellReuseIdentifier:@"mycell"];
b = YES;
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 200, 30)];
nameLabel.tag =12;
然后通过tag的值来获取控件
UILabel *nameLabel =(UILabel *)[cell.contentView viewWithTag:12];
2、创建一个MyCell类继承UITableViewCell类,然后重写初始化函数
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(5, 30, 68, 68)];
imageview.tag =11;
[self.contentView addSubview:imageview];
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 200, 30)];
nameLabel.tag =12;
[self.contentView addSubview:nameLabel];
UILabel *nickLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 40, 200, 30)];
nickLabel.tag =13;
[self.contentView addSubview:nickLabel];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 75, 200, 30)];
dateLabel.tag =14;
[self.contentView addSubview:dateLabel];
}
return self;
}
3、通过xib创建,但是需要向tableview中注册,在控制器cellForRowAtIndexPath函数中注册
if (!b) {
UINib *nib = [UINib nibWithNibName:@"Cell" bundle:[NSBundle mainBundle]];
[tableView registerNib:nib forCellReuseIdentifier:@"mycell"];
b = YES;
}
- tableView的单元格的定制的方法
- 定制单元格的用户界面。
- 定制UITableView的单元格
- TableView单元格的颜色对话框
- tableview单元格的复用
- JAVAFX的TableView的单元格可编辑
- 单元格的三种定制方式
- 定制单元格的几种方式
- TableView 的方法详解
- tableView的一些方法
- tableview的调用方法
- tableView的优化方法
- tableview列表中的cell单元格有倒计时的情况处理
- 让tableView的单元格分割线紧贴左边
- IOS_简单创建tableView并使用自定义的单元格
- Swift tableview 单元格分割线显示不全的解决方法
- Swift - 使用TableView的静态单元格进行页面布局
- 单元格的编辑的方法
- (拓扑排序11.3.1)POJ 1270 Following Orders(拓扑排序: 求变量串在约束组的作用下产生的有序集)
- ISE 12.3环境下出错“ this signal is connected to multiple drivers”
- SVN错误号对应问题
- 通过加载ip_nat_pptp模块使iptables支持PPTP穿透
- pjsip: 修改SDP的属性
- tableView的单元格的定制的方法
- 8 个最佳 PHP 库
- 分享android开发过程中用到的一些开源框架
- js加载
- android平台phonegap开发中使用EmailComposer插件发送邮件带附件失败的问题总结
- mutable使用方法——From百科
- relink all的摘抄
- Virtual Networking
- JBoss 系列一:软件安装及资料下载