Ios 项目从头开发 MVVM模式(三)
1.话说,本来想做个聚合查询功能。可是我的重点想研究xmpp聊天功能。所以使用mvvm模式做了全然模式51job主界面的页面。
2.首先给大家看我执行起来的界面。
3.界面非常easy,做这个界面主要是为了比較mvvm模式和mvc模式之间的差别。
4.这个界面的结构是下边这张图片
与mvc相比,我多了一个viewmodel文件。
mvc之前是把业务逻辑和数据放在viewcontroller里边,逻辑复杂的话,别人维护起来非常麻烦。
我就不贴viewcontroller的图片了,我把这个代码上传给大家,大家能够看看,和mvc相比,是不是非常easy维护。代码层级会好一些。明天開始研究iosxmpp的聊天功能,所以会暂停一段时间更新。
没办法,看来仅仅能贴代码了,我仅仅贴viewcontroller和viewmodel的代码。大家能够比較下。
这是viewcontroller
#import <UIKit/UIKit.h>
@class MTSOnlineViewModel;
@interface MTSOnlineViewController :UITableViewController
@property(strong,nonatomic)MTSOnlineViewModel *onlineViewModel;
@end
#import "MTSOnlineViewController.h"
#import "MTSOnlineViewModel.h"
#import "MTSOnlineMenuCell.h"
@interface
MTSOnlineViewController()<MTSOnlineMenuDelegate>
@end
@implementation MTSOnlineViewController
#pragma mark - UIViewController Overrides
- (void)awakeFromNib
{
[superawakeFromNib];
}
- (void)viewDidLoad
{
[superviewDidLoad];
self.onlineViewModel=[[MTSOnlineViewModelalloc]
init];
[self.tableViewsetRowHeight:130.0f];
[self.tableViewsetSeparatorStyle:UITableViewCellSeparatorStyleNone];
@weakify(self);
[self.onlineViewModel.updatedContentSignalsubscribeNext:^(id
x) {
@strongify(self);
[self.tableViewreloadData];
}];
}
-(void)viewWillAppear:(BOOL)animated {
[superviewWillAppear:animated];
self.onlineViewModel.active =YES;
}
#pragma mark - Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.onlineViewModelnumberOfItems];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
MTSOnlineMenuCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"onlinecell"forIndexPath:indexPath];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.delegate=self;
];
return cell;
}
#pragma mark --cell delegate
-(void)pressMenuButton:(MTSMenuType)type title:(NSString*)title;
{
[[[UIAlertViewalloc]
initWithTitle:@"button測试"message:title
delegate:nilcancelButtonTitle:@"确认"otherButtonTitles:nil,nil]
show];
}
@end
这是viewmodel
#import "RVMViewModel.h"
@interface MTSOnlineViewModel :RVMViewModel
@property (nonatomic,readonly)
RACSignal *updatedContentSignal;
@property (nonatomic,readonly)
NSMutableArray *tableDataSource;
-(NSInteger)numberOfItems;
@end
#import "MTSOnlineViewModel.h"
#import "MTSMenuModel.h"
@interface
MTSOnlineViewModel ()
@property (nonatomic,strong)
RACSubject *updatedContentSignal;
@property (nonatomic,strong)
NSMutableArray *tableDataSource;
@end
@implementation MTSOnlineViewModel
-(instancetype)init {
self = [superinit];
if (self ==nil)
returnnil;
self.updatedContentSignal = [[RACSubjectsubject]
setNameWithFormat:@"MTSOnlineViewModel updatedContentSignal"];
self.tableDataSource = [[NSMutableArrayalloc]
init];
@weakify(self)
[self.didBecomeActiveSignalsubscribeNext:^(id
x) {
@strongify(self);
[selfmenuDataSource];
}];
return
self;
}
#pragma mark - Public Methods
-(NSInteger)numberOfItems{
;
==?count:count+;
}
-(void)menuDataSource{
[self.tableDataSourceaddObject:[[MTSMenuModelalloc]
init:@"职位搜索"imagePath:@"jobsearch.png"imagePressPath:@"jobsearch_press.png"type:JobSearch]];
[self.tableDataSourceaddObject:[[MTSMenuModelalloc]
init:@"校园招聘"imagePath:@"campus.png"imagePressPath:@"campus_press.png"type:Campus]];
[self.tableDataSourceaddObject:[[MTSMenuModelalloc]
init:@"职场资讯"imagePath:@"worknews.png"imagePressPath:@"worknews_press.png"type:WorkNews]];
[self.tableDataSourceaddObject:[[MTSMenuModelalloc]
init:@"企业粉丝团"imagePath:@"fans.png"imagePressPath:@"fans_focus.png"type:Fans]];
[self.tableDataSourceaddObject:[[MTSMenuModelalloc]
init:@"My 51job"imagePath:@"my51job.png"imagePressPath:@"my51job_focus.png"type:My51Job]];
[self.tableDataSourceaddObject:[[MTSMenuModelalloc]
init:@"简历中心"imagePath:@"resumecenter.png"imagePressPath:@"resumecenter_focus.png"type:Resumecenter]];
[self.tableDataSource addObject:[[MTSMenuModel alloc] init:@"薪酬咨询"
imagePath:@"salaryquery.png" imagePressPath:@"salaryquery_focus.png" type:Salaryquery]];
[self.tableDataSource addObject:[[MTSMenuModel alloc] init:@"申请记录"
imagePath:@"jobapply.png" imagePressPath:@"jobapply_focus.png" type:JobApply]];
[self.tableDataSource addObject:[[MTSMenuModel alloc] init:@"很多其它"
imagePath:@"themore.png" imagePressPath:@"themore_focus.png" type:TheMore]];
}
@end
Ios 项目从头开发 MVVM模式(三)的更多相关文章
- 在iOS项目中引入MVVM
本文翻译自:http://www.objc.io/issue-13/mvvm.html.为了方便读者并节约时间,有些不是和文章主题相关的就去掉了.如果读者要看原文的话可以通过前面的url直接访问.作者 ...
- IOS的MVC和MVVM模式简明介绍
iOS中的MVC(Model-View-Controller)将软件系统分为Model.View.Controller三部分,结构图如下: Model: 你的应用本质上是什么(但不是它的展示方式) C ...
- IOS项目之分层MVVM
在做.Net时,有用到三层架构,使项目分层.ios项目使用AFNetWork把网络层这块也放进了ViewController中,数据解析缓存这些也在里面,这样层次结构可能不够清楚,今天就试着分离了一下 ...
- IOS项目之弹出动画三
前面写了弹出动画两个,今天做商城时又用到了,看着这个用着蛮普遍的,所以记了下来 // // mallMoreView.h // XQB // // Created by City--Online on ...
- Swift开发iOS项目实战视频教程(一)---iOS真简单
本课主要介绍iOS项目的创建.第一个iOS项目的开发.UILabel.UIButton的使用. 假设你看完此视频还认为iOS非常难,请你来找我! 本教程摒弃枯燥的语法和知识解说,全是有趣有料的项目实战 ...
- iOS学习——iOS项目Project 和 Targets配置详解
最近开始学习完整iOS项目的开发流程和思路,在实际的项目开发过程中,我们通常需要对项目代码和资料进行版本控制和管理,一般比较常用的SVN或者Github进行代码版本控制和项目管理.我们iOS项目的开发 ...
- MVVM模式应用体会
转自:http://www.cnblogs.com/626498301/archive/2011/04/08/2009404.html 进公司实习工作后,本人接触的第一个技术名语就是MVVM模式,从学 ...
- IOS项目之弹出动画终结篇
在之前写过IOS项目之弹出动画一.IOS项目之弹出动画二.IOS项目之弹出动画三,今天来一个终极封装已经上传到Github上弹出动画总结篇UIPopoverTableView. UIPopoverTa ...
- MVVM 模式下iOS项目目录结构详细说明
➠更多技术干货请戳:听云博客 我们在做项目的时候,会经常用到各种设计模式,最常见的要数 MVC (模型,视图,控制器)了.但是,今天我们要说的是另一种设计模式——MVVM. 所以 MVVM 到底是什么 ...
随机推荐
- CentOS 6及7 丢失root密码解决方案
6.x系列 法一:使用光盘镜像 BIOS中设置CD-ROM启动——选择救援模式——系统被自动挂载到/mnt/sysimage下——选择进入shell start shell——进入shell命令行—— ...
- 条款32:确定你的public继承塑模出is-a 关系(Make sure public inheritacne models "is-a")
NOTE : 1."public继承"意味is-a.适用于base classes 身上的每一件事一定也适用于derived classes身上,因为每一个derived cla ...
- Linux常用命令大全--有关磁盘空间的命令
1.mount 命令的功能是挂载文件系统,可以挂载硬盘.光盘.软盘,也可以挂载NFS网络文件系统 mount -t 设备类型 存放目录 mount IP地址:/所提供的目录 存放目录 (无) 不加任何 ...
- OI中的小智慧
反正不会咕咕的. sort之类没+1的问题不说 双向边n*2的问题不说 变量n+5的问题不说 1.先生成后判断 (见NOIP 2016 pj t2回文日期) 这个思想在这道题体现的不明显,记得洛谷上面 ...
- MyBatis 3 分页
利用MyBatis 3进行分页,选定的数据库表c_province,有3列,id列,provinceid列,province列,用Oracle数据库.首先建立一个对应的实体类,Province有3个属 ...
- luogu3415 祭坛
先二分答案转化成判定问题. 考虑拿一根扫描线从 \(x=0\) 扫到 \(x=n\),每次移动扫描线更新每个位置它上面的点数和下面的点数,这样可以确定在当前的扫描线上哪些位置对于 \(y\) 轴方向是 ...
- 大数据学习——linux常用命令(三)
三 文件操作 1创建文件 touch somefile.txt 创建一个空文件somefile.txt > 重定向操作符 echo "woshiwoa"> some.t ...
- Leetcode 297.二叉树的序列化和反序列化
二叉树地序列化和反序列化 序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据. ...
- iRule Event Order - HTTPv12
- UML的关联(Association), 聚合(Aggregation), 组合(Composition)区别
转载:http://blog.csdn.net/ocean181/article/details/6117369 UML的关联(Association), 聚合(Aggregation), 组合(Co ...