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模式(三)的更多相关文章

  1. 在iOS项目中引入MVVM

    本文翻译自:http://www.objc.io/issue-13/mvvm.html.为了方便读者并节约时间,有些不是和文章主题相关的就去掉了.如果读者要看原文的话可以通过前面的url直接访问.作者 ...

  2. IOS的MVC和MVVM模式简明介绍

    iOS中的MVC(Model-View-Controller)将软件系统分为Model.View.Controller三部分,结构图如下: Model: 你的应用本质上是什么(但不是它的展示方式) C ...

  3. IOS项目之分层MVVM

    在做.Net时,有用到三层架构,使项目分层.ios项目使用AFNetWork把网络层这块也放进了ViewController中,数据解析缓存这些也在里面,这样层次结构可能不够清楚,今天就试着分离了一下 ...

  4. IOS项目之弹出动画三

    前面写了弹出动画两个,今天做商城时又用到了,看着这个用着蛮普遍的,所以记了下来 // // mallMoreView.h // XQB // // Created by City--Online on ...

  5. Swift开发iOS项目实战视频教程(一)---iOS真简单

    本课主要介绍iOS项目的创建.第一个iOS项目的开发.UILabel.UIButton的使用. 假设你看完此视频还认为iOS非常难,请你来找我! 本教程摒弃枯燥的语法和知识解说,全是有趣有料的项目实战 ...

  6. iOS学习——iOS项目Project 和 Targets配置详解

    最近开始学习完整iOS项目的开发流程和思路,在实际的项目开发过程中,我们通常需要对项目代码和资料进行版本控制和管理,一般比较常用的SVN或者Github进行代码版本控制和项目管理.我们iOS项目的开发 ...

  7. MVVM模式应用体会

    转自:http://www.cnblogs.com/626498301/archive/2011/04/08/2009404.html 进公司实习工作后,本人接触的第一个技术名语就是MVVM模式,从学 ...

  8. IOS项目之弹出动画终结篇

    在之前写过IOS项目之弹出动画一.IOS项目之弹出动画二.IOS项目之弹出动画三,今天来一个终极封装已经上传到Github上弹出动画总结篇UIPopoverTableView. UIPopoverTa ...

  9. MVVM 模式下iOS项目目录结构详细说明

    ➠更多技术干货请戳:听云博客 我们在做项目的时候,会经常用到各种设计模式,最常见的要数 MVC (模型,视图,控制器)了.但是,今天我们要说的是另一种设计模式——MVVM. 所以 MVVM 到底是什么 ...

随机推荐

  1. C#对象初始化的探讨

    最近在弄MQ的性能监测数据埋点,无疑中用到一个Nstatsd的客户端,看到里面写过里面一种嵌套类的写法.代码如下: 客户端Client是一个密封的类,并且构造函数私有访问.然后又用一个嵌套类Curre ...

  2. new命令的原理

    function Person(name, age) { this.name = name; this.age = age } var person = new Person('小明', 18); c ...

  3. 搭建Mysql主从复制

    mysql 主从复制流程图 Server version: 10.0.24-MariaDB-7 Ubuntu 16.04 Master 记录二进制文件 导出数据并记录二进制位置 导入数据,设置二进制位 ...

  4. js的闭包中关于执行环境和作用链的理解

    首先讲一讲执行环境: 执行环境按照字面上来理解就是指目前代码执行所在的环境. 当JavaScript代码执行的时候,会进入不同的执行上下文,这些执行上下文会构成了一个执行上下文栈(Execution ...

  5. POJ 2485 Highways (求最小生成树中最大的边)

    Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...

  6. jenkins 提示No emails were triggered

    发送邮件 Jenkins->系统管理->系统设置,在“邮件通知”里设置smtp服务器地址,以及发送者邮箱地址,在具体的任务构建完成以后,可以设置发送邮件,在某一个任务的"Add ...

  7. xtu DP Training C.炮兵阵地

    炮兵阵地 Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 11856 ...

  8. XV内存变化

  9. 【java】基础语法

    集合   单线程 并发 Lists ArrayList——基于泛型数组 LinkedList——不推荐使用 Vector——已废弃(deprecated) CopyOnWriteArrayList—— ...

  10. C. The Smallest String Concatenation-C++sort排序~~

    C. The Smallest String Concatenation time limit per test 3 seconds memory limit per test 256 megabyt ...