给自定义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

上一篇:MATLAB cell 数组介绍


下一篇:MATLAB cell & struct