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 到底是什么 ...
随机推荐
- 生成 Let's Encrypt 免费https证书
1.打开 SSL For Free 官网:https://www.sslforfree.com/ 2.在输入框内输入你要申请证书的域名,输入完点击 Create Free SSL Certificat ...
- LeetCode(86) Partition List
题目 Given a linked list and a value x, partition it such that all nodes less than x come before nodes ...
- Mac OS X 上如何切换默认的 Python 版本?
- 【Codeforces 1141E】Superhero Battle
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 二分最后轮了几圈. 二分之后直接o(N)枚举具体要多少时间即可. 注意爆long long的情况. 可以用对数函数,算出来有多少个0 如果大于 ...
- centos7.4下搭建JDK+Tomcat+Nginx+Mysql+redis+Mongodb+maven+Git+Jenkins
先干两件大事!先干两件大事!先干两件大事! 1.关闭selinux [root@mycentos ~]# vi /etc/selinux/config SELINUX=disabled 2.关闭防火墙 ...
- 【Ajax 4】Ajax、JavaScript和JQuery的联系和区别
导读:在之前,就分别学习了Ajax.JavaScript和JQuery,然后对于这三者之间的关系,是一直云里雾里的.尤其是后来学到了Ajax,就更是不明白了.现在,就给总结总结. 一.基本概述 1.1 ...
- HDU 4405 飞行棋上的数学期望
突然发现每次出现有关数学期望的题目都不会做,就只能找些虽然水但自己还是做不出的算数学期望的水题练练手了 题目大意: 从起点0点开始到达点n,通过每次掷色子前进,可扔出1,2,3,4,5,6这6种情况, ...
- 【转载】ubuntu16.04 无线/Wifi 上网速度慢的解决方法
原文链接:http://tieba.baidu.com/p/4737599703[侵删] 一直以为是域名解析的问题,可也觉得不像.今天在百度搜索“ubuntu16.04域名解析慢”的时候无意中看到了h ...
- IdHttp 资料
http://blog.csdn.net/delphizhou/article/details/3085704 IdHttp 资料 网上找了些不过很不好找.今天找了些收藏在一起.以便他人查阅, idh ...
- markdown八条基础语法
1.空行 答:使用全角打出空格,之后再换行就可以打出空行了 2.标题 答:#表示标题,#表示一级标题,字号最大,一共有六级标题 3.列表 答:- 无序列表,1. 有序列表,注意和文本之间有空格 4.链 ...