//
// 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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。