M模型
V视图
C控制器
MVC是一种设计模式 通过model把Controller里面的东西拿出来 再用model 赋值到视图中 再把试图加载到Controller里面 (个人理解)
MVC 在小项目的时候不会显示它的优势 要让视图和数据完全分离 并不是特别的简单 这种设计模式会让程序的结构相对的稳定也会增加难度
再解析数据的时候 我们通常会直接加载到控制器里面的视图中 但是如果要加载的东西多了 我们的代码量也会成倍的增加 通过这种设计模式 会让我们的代码量少很多
在控制器里面解析到数据存入model里面
BaseModel * model = [[BaseModel alloc]init];
[model setValuesForKeysWithDictionary:dic];
[self.dataSource addObject:model];
在通过View调用到model里面的数据
在自定义视图当中自定义方法loadDataFromModel::(BaseModel *)model
-(void)loadDataFromModel:(BaseModel *)model{
if (model) {
self.titleLabel.text = model.title;
[self.imgV sd_setImageWithURL:[NSURL URLWithString:model.imgsrc]];
self.digestLabel.text = model.digest;
self.replayCountLabel.text = [NSString stringWithFormat:@"%@d评价",model.replyCount];
}
}
在控制器里面在调用
BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cells"];
if (self.dataSource.count>0) {
BaseModel * model = self.dataSource[indexPath.row];
[cell loadDataFromModel:model];
}