IOS学习之——自定义的Cell (代码)
来源:互联网 发布:域名邮箱怎么做 编辑:程序博客网 时间:2024/04/30 03:56
//***************************************************************************** 04 自定义的 cell //目的是来显示消息的 微博项目: 步骤:1.创建一个CZMicroBlogCell 继承UITableViewCell 2.导入头文件 #import "CZMicroBlogCell.h"//(在ViewController.m 中) 3.接着写数据源的方法 // 具体操作参考 04-实现数据源的方法 设置组//如果只有一组的话 就可以不用写这行代码 return 1; 设置行 设置cell (1)//创建可重用的自定义cell CZMicroBlogCell *cell =[CZMicroBlogCell microBlogCellWithTableView:tableView]; (2)//设置子控件的值 CZMicroBlogCell *microBlog =self.microBlogs[indexPath.row]; cell.microBlog =microBlog;//它应该提供一个模型属性 (3)//返回 return cell; // 因为没有 microBlog 属性 和microBlogCellWithTableView 类方法 所以我们要去写 //(在ViewController.h 中) @class CZMicroBlog; @property(nonatomic,copy) CZMicroBlog *microBlog; +(instancetype)microBlogCellWithTableView:(UITableView *)tableView; //(在CZMicroBlogCell.m中)实现这个类方法// QQ项目 //1 创建自定义可重用cell的对象 + (instancetype)messageCellWithTableView:(UITableView *)tableView { static NSString *reuseId = @"msg"; CZMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId]; if (cell == nil) { cell = [[CZMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId]; } return cell; } //2 创建子控件 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { //时间 UILabel *timeView = [[UILabel alloc] init]; [self.contentView addSubview:timeView]; self.timeView = timeView; //头像 UIImageView *iconView = [[UIImageView alloc] init]; [self.contentView addSubview:iconView]; self.iconView = iconView; //聊天内容 UIButton *textView = [[UIButton alloc] init]; [self.contentView addSubview:textView]; self.textView = textView; } return self; } //3 重写属性的setter方法 - (void)setMessage:(CZMessage *)message { _message = message; } @end //没办法算高度 所以要创建一个frame 模型 类名字 CZMessageFrame 继承 NSObject
0 0
- IOS学习之——自定义的Cell (代码)
- IOS学习之——自定义的Cell
- iOS开发UITableView 之代码自定义cell的步骤
- iOS学习总结----通过代码自定义cell(cell的⾼度不⼀致)
- 献给初学iOS的小盆友们——微博app项目开发之十二自定义cell代码补全
- IOS学习之——Cell自定义内容视图&自定义辅助视图
- iOS开发学习之自定义cell
- iOS代码自定义UITableView Cell(每个Cell的高度不一样)
- IOS学习 Cell自定义
- IOS之自定义Cell
- iOS通过代码自定义cell(cell的高度不同)的步骤
- iOS菜鸟学习——通过nib文件自定义Cell
- iOS菜鸟学习——storyboard中自定义cell
- iOS 代码自定义cell示例
- iOS开发之有趣的UI —— 自定义不等高cell
- 通过代码自定义cell(cell的高度不一致)
- 猫猫学IOS(十七)UI之纯代码自定义Cell实现新浪微博UI
- AJ学IOS(17)UI之纯代码自定义Cell实现新浪微博UI
- tableView小技巧:让cell分割线充满整个cell,去掉多余的分割线
- mysql 分表
- Java核心知识点-JVM结构之常量池
- CocoaPods安装和使用及问题:Setting up CocoaPods master repo
- sqrt源代码问题——二分法
- IOS学习之——自定义的Cell (代码)
- 重装系统关于diskgenius分区工具
- hdu1162Eddy's picture
- Tomcat7+redis Session共享
- 码农小汪-剑指Offer之16-二叉树的镜像
- Win10环境下VS2015+opencv3.1.0配置
- Oracle之高级查询
- 第十四章 c++中的代码重用
- IOS学习之—— xib的用法--自定义View