给自定义cell赋值代码
//
// ViewController.m
// 11 - 投资管理 - 李洪强
//
// Created by vic fan on 16/4/8.
// Copyright © 2016年 李洪强. All rights reserved.
//
#define SCREENW [UIScreen mainScreen].bounds.size.width
#define SCREENH [UIScreen mainScreen].bounds.size.height
#import "ViewController.h"
//投资标详情
#import "LHQInvestmentTargetsCtrl.h"
#import "LHQInvestmentManagementCell.h"
#import "LHQInvestmentManagementModel.h"
//已完成
#import "LHQCompletedCtrl.h"
//未满标
#import "LHQNotFullMarkCtrl.h"
@interface ViewController ()<UITabBarControllerDelegate,UITableViewDataSource>
@property(nonatomic)NSMutableArray *dataArr;
@end
@implementation ViewController
-(NSMutableArray *)dataArr
{
if (!_dataArr) {
_dataArr = [[NSMutableArray alloc] init];
}
return _dataArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"投资管理";
//如果tableView启用分组的话。第一组之前会有空白。把空白去掉
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 17)];
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:64/255.0 green:41/255.0 blue:96/255.0 alpha:1.0]];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
[self.tableView registerNib:[UINib nibWithNibName:@"LHQInvestmentManagementCell" bundle:nil] forCellReuseIdentifier:@"LHQInvestmentManagementCell"];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self createData];
}
//数据
- (void)createData{
//循环给每一个cell里面的数据数组赋值
for (int i=0; i<4; i++) {
LHQInvestmentManagementModel *model = [[LHQInvestmentManagementModel alloc] init];
NSDictionary *dic = [NSDictionary dictionaryWithObjects:@[@"Snip20160415_11",@"世界那么大,我想去看看",@"还款中",@"12000.00",@"3000.00",@"986.12"] forKeys:@[@"stutes",@"title",@"bidStutes",@"assets",@"invest",@"lastone"]];
[model setValuesForKeysWithDictionary:dic];
[self.dataArr addObject:model];
}
//把模型model放到数据数组中
[self.tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// NSLog(@"%zd,%zd",indexPath.section,indexPath.row);
//点击某一行cell跳转到投资标详情
UIStoryboard *CZStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LHQInvestmentManagementModel *model = self.dataArr[indexPath.section];
//用模型数据给标的状态赋值
// CZVC.StateLabel = model.bidStutes;
if([model.bidStutes isEqualToString:@"还款中"]){
LHQInvestmentTargetsCtrl *CZVC = [CZStoryboard instantiateViewControllerWithIdentifier:@"LHQInvestmentTargetsCtrl"];
CZVC.StateLabel = model.bidStutes;
[self.navigationController pushViewController:CZVC animated:YES];
}else if ([model.bidStutes isEqualToString:@"已还款"]){
LHQCompletedCtrl *CVC = [CZStoryboard instantiateViewControllerWithIdentifier:@"LHQCompletedCtrl"];
CVC.StateLabel2 = model.bidStutes;
[self.navigationController pushViewController:CVC animated:YES];
}else {
LHQNotFullMarkCtrl *NVC = [CZStoryboard instantiateViewControllerWithIdentifier:@"LHQNotFullMarkCtrl"];
NVC.StateLabel3 = [ViewController loanStatusWithCode:14];;
[self.navigationController pushViewController:NVC animated:YES];
}
}
//组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
//每一行显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellTableIdentifier = @"LHQInvestmentManagementCell";
LHQInvestmentManagementCell *cell = [tableView dequeueReusableCellWithIdentifier:
CellTableIdentifier forIndexPath:indexPath];
if (cell == nil)
{
cell = [[LHQInvestmentManagementCell alloc] init] ;
}
LHQInvestmentManagementModel *model = _dataArr[indexPath.section];
[cell customedWithModel:model];
return cell;
}
//每一行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//屏幕适配
if(SCREENH <= 480){
return 100;
}else if (SCREENH < 667){
return 100;
}else if (SCREENH == 667){
return 125;
}else {
return 150;
}
}
//借款状态对照码
+ (NSString *)loanStatusWithCode:(NSInteger)statusCode
{
NSString *loanStatusStr = nil;
switch (statusCode) {
case 0:{
loanStatusStr = @"审核中";
}
break;
case 1:{
loanStatusStr = @"提前借款";
}
break;
case 2:{
loanStatusStr = @"筹款中";
}
break;
case 3:{
loanStatusStr = @"待放款";
}
break;
case 4:{
loanStatusStr = @"还款中";
}
break;
case 5:{
loanStatusStr = @"已还款";
}
break;
case 10:{
loanStatusStr = @"审核中待验证";
}
break;
case 11:{
loanStatusStr = @"提前借款待验证";
}
break;
case 14:{
loanStatusStr = @"本金垫付还款中";
}
break;
case -10:{
loanStatusStr = @"未验证";
}
break;
case -100:{
loanStatusStr = @"资金托管提交中";
}
break;
case -5:{
loanStatusStr = @"撤销";
}
break;
case -4:{
loanStatusStr = @"流标";
}
break;
case -3:{
loanStatusStr = @"放款不通过";
}
break;
case -2:{
loanStatusStr = @"审核不通过";
}
break;
case -1:{
loanStatusStr = @"审核不通过";
}
break;
default:{
loanStatusStr = [NSString stringWithFormat:@"%zd",statusCode];
}
break;
}
return loanStatusStr;
}
@end
//
// LHQInvestmentManagementCell.h
// 11 - 投资管理 - 李洪强
//
// Created by vic fan on 16/4/15.
// Copyright © 2016年 李洪强. All rights reserved.
//
#import <UIKit/UIKit.h>
@class LHQInvestmentManagementModel;
@interface LHQInvestmentManagementCell : UITableViewCell
-(void)customedWithModel:(LHQInvestmentManagementModel *)model;
@end
//
// LHQInvestmentManagementCell.m
// 11 - 投资管理 - 李洪强
//
// Created by vic fan on 16/4/15.
// Copyright © 2016年 李洪强. All rights reserved.
//
#define SCREENW [UIScreen mainScreen].bounds.size.width
#define SCREENH [UIScreen mainScreen].bounds.size.height
#import "LHQInvestmentManagementCell.h"
//模型数据
#import "LHQInvestmentManagementModel.h"
#import "ViewController.h"
@interface LHQInvestmentManagementCell ()
//1 标识图片
@property (weak, nonatomic) IBOutlet UIImageView *IdentificationImage;
//主标题
@property (weak, nonatomic) IBOutlet UILabel *MainTitleLabel;
//2 标的状态
@property (weak, nonatomic) IBOutlet UILabel *TargetStateLabel;
//3 总额数字
@property (weak, nonatomic) IBOutlet UILabel *TotalLabel;
@property (weak, nonatomic) IBOutlet UILabel *TotalTextLabel;
//4 我的投资额下
@property (weak, nonatomic) IBOutlet UILabel *MyInvestmentAmountLabel;
//5 待收总额
@property (weak, nonatomic) IBOutlet UILabel *TotalAmountToBeCollected;
//最后的label
@property (weak, nonatomic) IBOutlet UILabel *lastLabel;
//图标
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ImageX;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ImageY;
//主标题
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MainTitleLabelX;
//标的状态
//标的状态宽
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *BidStatuesW;
//标的状态高
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *BidStatuesH;
//标的状态X
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *BidStatuesX;
//总额
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TotalLabelY;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TotalLabelX;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *TotalNumY;
//我的投资额上
@property (weak, nonatomic) IBOutlet UILabel *MyInvestmentAmount;
//上
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MyInvestmentAmountX;
//下
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MyInvestmentAmountLabelX;
//待收总额
@property (weak, nonatomic) IBOutlet UILabel *TotalAmountLabel;
@end
@implementation LHQInvestmentManagementCell
//布局子控件- 屏幕适配
- (void)layoutSubviews{
if(SCREENH <= 480){
self.ImageX.constant = 15;
self.ImageY.constant = 15;
self.MainTitleLabel.font = [UIFont systemFontOfSize:15];
self.MainTitleLabelX.constant = 5;
//标的状态
//标的状态label的宽
if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else{
self.BidStatuesW.constant = 65;
}
// self.BidStatuesW.constant = 60;
self.BidStatuesH.constant = 20;
self.TargetStateLabel.font = [UIFont systemFontOfSize:12];
//总额
self.TotalLabelX.constant = 15;
self.TotalLabelY.constant = 15;
self.TotalTextLabel.font = [UIFont systemFontOfSize:13];
self.TotalLabel.font = [UIFont systemFontOfSize:13];
//我的投资额
self.MyInvestmentAmount.font = [UIFont systemFontOfSize:13];
//待收总额
self.TotalAmountLabel.font = [UIFont systemFontOfSize:13];
//
self.TotalNumY.constant = 3;
self.MyInvestmentAmountLabel.font = [UIFont systemFontOfSize:13];
self.TotalAmountToBeCollected.font = [UIFont systemFontOfSize:13];
}else if (SCREENH < 667){
self.ImageX.constant = 15;
self.ImageY.constant = 15;
self.MainTitleLabel.font = [UIFont systemFontOfSize:15];
self.MainTitleLabelX.constant = 5;
//标的状态
//标的状态label的宽
if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){
self.BidStatuesW.constant = 90;
self.BidStatuesX.constant = 5;
}else{
self.BidStatuesW.constant = 65;
}
// self.BidStatuesW.constant = 60;
self.BidStatuesH.constant = 20;
self.TargetStateLabel.font = [UIFont systemFontOfSize:12];
//总额
self.TotalLabelX.constant = 15;
self.TotalLabelY.constant = 15;
self.TotalTextLabel.font = [UIFont systemFontOfSize:13];
self.TotalLabel.font = [UIFont systemFontOfSize:13];
//我的投资额
self.MyInvestmentAmount.font = [UIFont systemFontOfSize:13];
//待收总额
self.TotalAmountLabel.font = [UIFont systemFontOfSize:13];
//
self.TotalNumY.constant = 3;
self.MyInvestmentAmountLabel.font = [UIFont systemFontOfSize:13];
self.TotalAmountToBeCollected.font = [UIFont systemFontOfSize:13];
}else if (SCREENH == 667){
//标的状态label的宽
if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){
self.BidStatuesW.constant = 110;
}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){
self.BidStatuesW.constant = 110;
}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){
self.BidStatuesW.constant = 110;
}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){
self.BidStatuesW.constant = 110;
}else{
self.BidStatuesW.constant = 80;
}
self.BidStatuesX.constant = 40;
self.TotalNumY.constant = 5;
self.MyInvestmentAmountX.constant = 80;
self.MyInvestmentAmountLabelX.constant = 35;
}else {
//标的状态label的宽
if([self.TargetStateLabel.text isEqualToString:@"审核中待验证"]){
self.BidStatuesW.constant = 110;
}else if ([self.TargetStateLabel.text isEqualToString:@"提前借款待验证"]){
self.BidStatuesW.constant = 110;
}else if ([self.TargetStateLabel.text isEqualToString:@"本金垫付还款中"]){
self.BidStatuesW.constant = 110;
}else if ([self.TargetStateLabel.text isEqualToString:@"资金托管提交中"]){
self.BidStatuesW.constant = 110;
}else{
self.BidStatuesW.constant = 80;
}
self.BidStatuesX.constant = 70;
self.TotalNumY.constant = 5;
self.MyInvestmentAmountX.constant = 100;
self.MyInvestmentAmountLabelX.constant = 55;
self.TotalLabelY.constant = 30;
}
}
- (void)customedWithModel:(LHQInvestmentManagementModel *)model{
/**
@property(nonatomic)NSString *stutes;
@property(nonatomic)NSString *title;
@property(nonatomic)NSString *bidStutes;
@property(nonatomic)NSString *assets;
@property(nonatomic)NSString *invest;
@property(nonatomic)NSString *lastone;
*/
//1 标识图片
self.IdentificationImage.image = [UIImage imageNamed:model.stutes];
//2 大标题
self.MainTitleLabel.text = model.title;
//3 标的状态
self.TargetStateLabel.text = model.bidStutes;
// if([self.TargetStateLabel.text isEqualToString:@"还款中"]){
//
// self.TargetStateLabel.layer.masksToBounds = YES;
// self.TargetStateLabel.layer.cornerRadius = 6;
// self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];
//
//
// }else if ([self.TargetStateLabel.text isEqualToString:@"已逾期"]){
//
// self.TargetStateLabel.layer.masksToBounds = YES;
// self.TargetStateLabel.layer.cornerRadius = 6;
// self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];
//
//
// }else if ([self.TargetStateLabel.text isEqualToString:@"已完成"]){
// self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];
//
//
// self.TargetStateLabel.layer.masksToBounds = YES;
// self.TargetStateLabel.layer.cornerRadius = 6;
// self.lastLabel.text = @"收益总额";
// }else if ([self.TargetStateLabel.text isEqualToString:@"未满标"]){
// self.lastLabel.text = @"已完成";
// self.TargetStateLabel.layer.masksToBounds = YES;
// self.TargetStateLabel.layer.cornerRadius = 6;
//
// }
self.TargetStateLabel.backgroundColor = [UIColor colorWithRed:26/255.0 green:199/255.0 blue:62/255.0 alpha:1.0];
//
self.TargetStateLabel.layer.masksToBounds = YES;
self.TargetStateLabel.layer.cornerRadius = 6;
//4 总额
self.TotalLabel.text = model.assets;
//5 我的投资额
self.MyInvestmentAmountLabel.text = model.invest;
//6 待收总额
self.TotalAmountToBeCollected.text = model.lastone;
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
//
// LHQInvestmentManagementModel.h
// 11 - 投资管理 - 李洪强
//
// Created by vic fan on 16/4/15.
// Copyright © 2016年 李洪强. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface LHQInvestmentManagementModel : NSObject
//存放内容的数组
//1 图标
@property(nonatomic)NSString *stutes;
//2 大标题
@property(nonatomic)NSString *title;
//3 标的状态
@property(nonatomic)NSString *bidStutes;
//4 总额
@property(nonatomic)NSString *assets;
//5 我的投资额
@property(nonatomic)NSString *invest;
//6 待收金额
@property(nonatomic)NSString *lastone;
@end
//
// LHQInvestmentManagementModel.m
// 11 - 投资管理 - 李洪强
//
// Created by vic fan on 16/4/15.
// Copyright © 2016年 李洪强. All rights reserved.
//
#import "LHQInvestmentManagementModel.h"
@implementation LHQInvestmentManagementModel
@end
给自定义cell赋值代码的更多相关文章
- 给自定义cell赋值
搭建自定义cell-给自定义cell赋值的思路 1 主控制器 1.1导入头文件 #import "LHQInvestmentManagementCell.h" #import &q ...
- AJ学IOS(17)UI之纯代码自定义Cell实现新浪微博UI
AJ分享,必须精品 先看效果图 编程思路 代码创建Cell的步骤 1> 创建自定义Cell,继承自UITableViewCell 2> 根据需求,确定控件,并定义属性 3> 用get ...
- 李洪强iOS开发之自定义cell的使用
第一步: 创建自定义cell类,继承自UItableVIewcell 第二步: 在sb中布局自己需要的视图控件并且将此cell与我刚刚创建的cell类进行关联.并且连线 第三步: 创建modle类, ...
- iOS开发小技巧--纯代码自定义cell
纯代码自定义cell 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样) 1.新建一个继承自UITableViewCell的子类 2.在initWithStyle:方 ...
- 通过代码自定义cell 新浪微博页面显示
通过代码自定义cell(cell的高度不一致)(如果高度一致的cell 用xib实现) 1.新建一个集成自UItableVIewCell的类 2.重写initWithStle :方法 - (insta ...
- oc学习之路----通过代码自定义cell
需求背景:由于tableView中每一个cell的数据与布局都不一样,故不能用xib实现功能,这是用代码写自定义cell就有必要了. 步骤 1.新建一个继承自UITableViewCell的类 2.重 ...
- UITableView自定义Cell中,纯代码编程动态获取高度
在UITableView获取高度的代理方法中,经常需要根据实际的模型重新计算每个Cell的高度.直接的做法是在该代理方法中,直接根据模型来返回行高:另 [1]-(CGFloat)tableView:( ...
- iOS UI-微博案例(通过代码自定义Cell)
一.Model BWWeiBo数据模型 #import <Foundation/Foundation.h> @interface BWWeiBo : NSObject @property ...
- 懒加载 字典转模型 自定义cell
1 懒加载: 1> 什么是懒加载? 懒加载又称为延时加载,即在系统调用的时候加载,如果系统不调用则不会加载.所谓的懒加载其实就是重写其 get 方法. 2> 特点:在使用懒加载的时候要 ...
随机推荐
- FreeSWITCH 体系配置结构
转自:http://www.cnblogs.com/logo-fox/archive/2013/12/09/3465440.html FreeSWITCH总体结构: FreeSWITCH 由一个稳定的 ...
- Debian 的 preinst, postinst, prerm, 和 postrm 脚本
转自:http://jianjian.blog.51cto.com/35031/395468 这些是软件包安装前后自动运行的可执行脚本. 统称为控制文件, 是 Deian 软件包的"控制&q ...
- 在64位Win7中使用Navicat Premium 和PL\SQL Developer连接Oracle数据库备忘
最近接手了一个项目,服务器端数据库是oracle 11g 64位.由于主要工作不是开发,也不想在自己的电脑上安装庞大的oracle数据库,因此寻思着只通过数据库管理工具连接数据库进行一些常用的查询操作 ...
- 函数调用关于从Ring3转到Ring0 ESP堆栈变化
在ring0堆栈获取ring3堆栈方式 第一种方式 [esp+4] == [esp+参数个数*4+4] 如果这里不相等就需要用第二种方式 [[esp+参数个数*4+8]] 这里面的值就是Ring3的堆 ...
- 动态平衡二叉搜索树的简易实现,Treap 树
http://blog.csdn.net/qichi_bj/article/details/8232048
- 动态添加PopupWindow
动态添加PopupWindow的方法private void showPopupWindow() { LayoutInflater inflater = LayoutInflater.from(thi ...
- 利用pushState开发无刷页面切换
转载:http://www.cnblogs.com/flash3d/archive/2013/10/23/3384823.html 实现目标 页面的跳转(前进后退,点击等)不重新请求页面 页面URL与 ...
- 《DSP using MATLAB》示例Example4.5
代码: x1 = [1, 2, 3]; x2 = [2, 4, 3, 5]; % x1 x2 sequences % n1 = 0:1:2; n2 = 0:1:3; n1 = -1:1:1; n2 = ...
- loopback 04
数据库相关 关系定义 relationship 定义关系之后的使用 relations: { "images": { "type": "hasMany ...
- css3 -- 背景图处理
1.多背景图片: p{ background-image:url() , url(); background-position:95% 90% , 50% 50%; background-repect ...