tableView的单元格的定制的方法
2013-11-08 10:05
141 查看
1、在 cellForRowAtIndexPath 函数中创建
//定制单元格
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 200, 30)];
nameLabel.tag =12;
然后通过tag的值来获取控件
UILabel *nameLabel =(UILabel *)[cell.contentView viewWithTag:12];
2、创建一个MyCell类继承UITableViewCell类,然后重写初始化函数
- (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;
}
3、通过xib创建,但是需要向tableview中注册,在控制器cellForRowAtIndexPath函数中注册
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类,然后重写初始化函数
- (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;
}
3、通过xib创建,但是需要向tableview中注册,在控制器cellForRowAtIndexPath函数中注册
static BOOL b=NO;
if (!b) {
UINib *nib = [UINib nibWithNibName:@"Cell" bundle:[NSBundle mainBundle]];
[tableView registerNib:nib forCellReuseIdentifier:@"mycell"];
b = YES;
}
相关文章推荐
- Swift tableview 单元格分割线显示不全的解决方法
- 实现iOS7以前的TableViewGroupStyle的方法。
- iOS 导航条透明(以及自定义颜色)的方法,去掉导航条底部黑线,随着tableView滚动设置导航条变色
- IOS——TableView以及TableViewCell方法总结
- iOS 一个ViewController上显示2个tableView的方法
- Swift - tableView单元格高度自适应(图片宽度固定,高度自适应)
- 猫猫学iOS之tableView的下拉放大图片的方法
- iOS开发tableView分割线顶格,以及隐藏多余的单元格
- IOS7以上用UINavigationController 导致tableview下移解决方法
- 关于tableview高度自适应的一个方法
- 你真的懂得tableview cell的两个重用方法嘛
- 在tableview索引中显示搜索符号的方法
- Tableview 更多数据的显示方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- [EGORefreshTableHeaderView]手动启动下拉更新的方法
- IOS 中列表的TableView 详解,常用方法整理
- 关于viewController中的tableview的cell在pop回来后仍有选中效果的解决方法
- iOS tableView事件方法
- 为什么TableView 的代理方法cellForRowAtIndexPath 不执行问题
- tableview的两个重用cell方法