tableView-自定义非等高cell(1)
2015-08-15 01:14
239 查看
非等高的cell
xib自定义cell
storyboard自定义cell
代码自定义cell(frame)
代码自定义cell(Autolayout)
懒加载,面向模型开发,将字典转为模型,以后数据通过模型获得
实现数据源和代理类方法
自定义cell类(同时生成xib)
提供函数用于加载XIB文件,带有一个UITableView参数,用于cell缓冲池优化
从xib向类扩展拖线,获取到自定义布局的控件
提供数据接口,在获取数据的setter方法中,给控件赋值赋值
toryboard中的操作
普通控制器UIViewController控制器(自带一个view),添加tabView(推荐)
可以直接拖一个UITableViewController,但是里面有好多添加好的东西,不一定满足我们的要求,比如:一些需要添加一些工具栏等.
给控制器定义Class类型
给xib中的cell定义Class类型
设置cell的标示符
自定义控件,并AutoLayout自动布局添加约束.
自定义数据模型类
![](http://img.blog.csdn.net/20150815011728452)
xib自定义cell
storyboard自定义cell
代码自定义cell(frame)
代码自定义cell(Autolayout)
自定义非等高cell-xib(1)
布局内容,返回每一行的高度为固定值
常规设置
自定义控制器类懒加载,面向模型开发,将字典转为模型,以后数据通过模型获得
实现数据源和代理类方法
#import "WQViewController.h" #import "WQStatusData.h" #include "WQStatusCell.h" @interface WQViewController () /**数据*/ @property (nonatomic, strong) NSArray *statusData; @end @implementation WQViewController - (NSArray *)statusData { if (_statusData == nil) { NSArray *arrFromPlist = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"statuses.plist" ofType:nil]]; NSMutableArray *arr = [NSMutableArray array]; [arrFromPlist enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { WQStatusData *statusdata = [WQStatusData statusWithDict:obj]; [arr addObject:statusdata]; }]; _statusData = arr; } return _statusData; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.statusData.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WQStatusCell *cell = [WQStatusCell statusWithTableView:tableView]; cell.statusData = _statusData[indexPath.row]; return cell; } /** *返回每一行的高度 */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 250; } - (void)viewDidLoad { [super viewDidLoad]; } @end
自定义cell类(同时生成xib)
提供函数用于加载XIB文件,带有一个UITableView参数,用于cell缓冲池优化
从xib向类扩展拖线,获取到自定义布局的控件
提供数据接口,在获取数据的setter方法中,给控件赋值赋值
#import <UIKit/UIKit.h> @interface WQViewController : UITableViewController @end #import <UIKit/UIKit.h> @class WQStatusData; @interface WQStatusCell : UITableViewCell /** 数据*/ @property (nonatomic, strong) WQStatusData *statusData; + (instancetype)statusWithTableView:(UITableView *)tableview; @end #import "WQStatusCell.h" #import "WQStatusData.h" @interface WQStatusCell() @property (weak, nonatomic) IBOutlet UIImageView *iconImageView; @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UIImageView *pictureImageView; @property (weak, nonatomic) IBOutlet UIImageView *vipImageView; @property (weak, nonatomic) IBOutlet UILabel *contentLabel; @end @implementation WQStatusCell + (instancetype)statusWithTableView:(UITableView *)tableview { static NSString *ID = @"status"; WQStatusCell *cell = [tableview dequeueReusableCellWithIdentifier:ID]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil]lastObject]; } return cell; } - (void)setStatusData:(WQStatusData *)statusData { _statusData = statusData; if (self.statusData.isVip) { self.vipImageView.hidden = NO; self.nameLabel.textColor = [UIColor redColor]; }else { self.vipImageView.hidden = YES; self.nameLabel.textColor = [UIColor blackColor]; } if (_statusData.picture) { self.pictureImageView.hidden = NO; self.pictureImageView.image = [UIImage imageNamed:_statusData.picture]; }else { self.pictureImageView.hidden = YES; } self.iconImageView.image = [UIImage imageNamed:_statusData.icon]; self.nameLabel.text = _statusData.name; self.contentLabel.text = _statusData.text; } @end
toryboard中的操作
普通控制器UIViewController控制器(自带一个view),添加tabView(推荐)
可以直接拖一个UITableViewController,但是里面有好多添加好的东西,不一定满足我们的要求,比如:一些需要添加一些工具栏等.
给控制器定义Class类型
给xib中的cell定义Class类型
设置cell的标示符
自定义控件,并AutoLayout自动布局添加约束.
自定义数据模型类
#import <Foundation/Foundation.h> @interface WQStatusData : NSObject /**头像*/ @property (nonatomic, strong) NSString *icon; /**姓名*/ @property (nonatomic, strong) NSString *name; /** 内容*/ @property (nonatomic, strong) NSString *text; /**图片*/ @property (nonatomic, strong) NSString *picture; /** vip*/ @property (nonatomic, assign, getter = isVip) BOOL vip; + (instancetype)statusWithDict:(NSDictionary *)dict; @end @implementation WQStatusData + (instancetype)statusWithDict:(NSDictionary *)dict { WQStatusData *statusData = [[WQStatusData alloc]init]; [statusData setValuesForKeysWithDictionary:dict]; return statusData; } @end
相关文章推荐
- 菜单状态更新
- ArcGIS地质图矢量化技巧概要
- [置顶] Genymotion 出现the number of cpus of the virtual device has been forced to be 1的解决方法
- android:layout_weight详解
- arcgis切割多边形以及合并多边形
- 《金砖之国》
- UVA 12486 Space Elevator(数位DP)
- HDU 5387 Clock
- HDU1466 计算直线的交点数
- tableView - 自定义等高cell(frame和masonry方式)
- 八种排序算法(C语言简易版)
- tableView - 自定义等高cell-xib方式
- padding标准盒模型和怪异盒子模型
- hdu 5389 Zero Escape (dp)
- Swift-常量(let)和变量(var)
- HDU 5386 Cover(模拟)
- 快速排序的C++实现
- MFC动态创建菜单
- POJ - 3160 Father Christmas flymouse(最长路+强连通分量)
- UVA 12487 Midnight Cowboy(LCA+大YY)(好题)