//
// ViewController.m
// 07_08
//
// Created by Song on 2020/7/8.
// Copyright © 2020 Song. All rights reserved.
//
#import "ViewController.h"
#import <NSObject+YYModel.h>
#import "YYPersonModel.h"
@interface ViewController () <UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *good;
@end
@implementation ViewController
#pragma mark - 懒加载
- (NSMutableArray *) good {
if(_good == nil) {
NSMutableArray *arrayModels = [NSMutableArray array];
NSDictionary *dic = @{
@"name":@"Zhang San",
@"age":@(24),
@"sex":@"Man",
@"pic":@"coronavirus_02"
};
// 数据转模型
YYPersonModel *model = [YYPersonModel yy_modelWithDictionary:dic];
// 模型转数据
//NSDictionary *dics = [model yy_modelToJSONObject];
// NSLog(@"%@", model);//在类里面重写了description方法,使得可以输出,但是我在这输出不了。
[arrayModels addObject:model];
_good = arrayModels;
}
return _good;
}
#pragma mark - 数据源方法
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.good.count;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YYPersonModel *model = self.good[indexPath.row];
static NSString *ID = @"goods_cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
cell.imageView.image = [UIImage imageNamed:model.pic];
cell.textLabel.text = model.name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"性别:%@ 年龄:%d", model.sex, model.age];
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
@end
YYModel
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...