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 到底是什么 ...
随机推荐
- 配置github SSH公钥登录
git的安装见https://www.cnblogs.com/liliyang/p/9829931.html 配置git使用ssh密钥 git支持https和git两种传输协议,github分享链接时 ...
- rails使用bootstrap
在Gemfile文件中添加'bootstrap-sass',再运行bundle install gem 'bootstrap-sass' 在config/application.rb添加一行代码,让b ...
- Fiddler使用配置遇到的问题
针对Fiddler使用遇到的问题记录,方便后期再使用. 1.Chrome导入证书失败,提示"提示由于存储区只读的,存储区已满..." 方法:直接去控制台添加 详细参考:http:/ ...
- 【02】使用Firebug查看和编辑HTML和CSS
使用Firebug查看和编辑HTML和CSS 描述 在本章节的教程中,我们将讨论如何使用Firebug查看和编辑HTML和CSS. 使用Firebug查看和编辑HTML 在你要查看的元素上右击鼠标然后 ...
- laravel 文件删除
删除文件 <?php class demo{ public function del(){ $disk = Storage::disk('public');//获取磁盘实例 $disk-> ...
- gitHub网站上常见英语翻译2
repositories资料库 compilers with rich code analysis APIs.编译器具有丰富的代码分析API. plugins插件 With a variety of ...
- 两个很实用很方便的函数核心及用法{(lower_bound)+(max_element))~~
(1) 关于 lower_bound(a,a+n,x)-a的用法: 求x在数组a中的 ...
- FZU2206函数求解
Problem 2206 函数求解 Accept: 154 Submit: 456 Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- 【HDOJ6305】RMQ Similar Sequence(笛卡尔树)
题意: 给定一个数组a,现在存在一个数组b,其元素值在[0,1]随机生成 若对于a,b,任意rmq问题的最值出现在同一个数组中的位置,则数组b的价值为∑b[i],否则为0,求数组b的期望价值 n< ...
- BZOJ1126: [POI2008]Uci
$n \leq 100,m \leq 100$,$n*m$的01矩形,问从左下角开始往上走,每次转弯只能向右,不能经过重复点,不能撞到1,到达点$(x,y)$的方案数,$mod \ \ k$. 感人肺 ...