Ios 項目從頭開發 MVVM模式(三),iosmvvm
1.話說,本來想做個彙總查詢功能,但是我的重點想研究xmpp聊天功能。所以使用mvvm模式做了完全模式51job主介面的頁面。
2.首先給大家看我運行起來的介面。
3.介面很簡單,做這個介面主要是為了比較mvvm模式和mvc模式之間的區別。
4.這個介面的結構是下邊這張圖片
與mvc相比,我多了一個viewmodel檔案。
mvc之前是把商務邏輯和資料放在viewcontroller裡邊,邏輯複雜的話,別人維護起來很麻煩。
我就不貼viewcontroller的圖片了,我把這個代碼上傳給大家,大家可以看看,和mvc相比,是不是很容易維護,代碼層級會好一些。明天開始研究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;
[cell configureCell:self.onlineViewModel.tableDataSourceindex:indexPath.row+1];
return cell;
}
#pragma mark --cell delegate
-(void)pressMenuButton:(MTSMenuType)type title:(NSString*)title;
{
[[[UIAlertViewalloc]initWithTitle:@"按鈕測試"message:titledelegate: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{
NSUInteger count = [self.tableDataSourcecount]/3;
return [self.tableDataSourcecount]%3==0?count:count+1;
}
-(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
WPF 對於第三方控制項dev TreeListControl MVVM模式
blog.csdn.net/...537679,看看有協助沒
我是暗黑3的新手,這兩天才把劇情模式通關了,等級70級,不知道做什了,問是繼續提高難度從頭劇情
先打冒險刷箱子,調點裝備,忙後打苦痛一,之後苦痛三,忙後畢業,現在沒有特殊性裝備都是垃圾了,慢慢玩吧,慢慢試裝備搭配和技能這個遊戲的特色