MVVM mode developed from scratch in Ios (III), iosmvvm

Source: Internet
Author: User

MVVM mode developed from scratch in Ios (III), iosmvvm

1. In other words, I wanted to create an aggregate query function, but I wanted to focus on xmpp chat. Therefore, the mvvm mode is used to complete the page of the 51job main interface.

2. First, let's show you the running interface.


3. The interface is very simple. This interface is mainly used to compare the differences between the mvvm mode and the mvc mode.

4. The structure of this interface is the image below


Compared with mvc, I have an additional viewmodel file.

Previously, mvc put business logic and data in viewcontroller. If the logic is complex, it is difficult for others to maintain it.

I will not post viewcontroller images. I will upload this code to you. You can see if it is easier to maintain than mvc, and the code level will be better. The chat function of iosxmpp will be studied tomorrow, so the update will be paused for a while.

No way. It seems that you can only paste code. I only paste the code of viewcontroller and viewmodel. You can compare them.

This is 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. tableperformanceindex: indexPath. row + 1];

Return cell;

}


# Pragma mark -- cell delegate

-(Void) pressMenuButton :( MTSMenuType) type title :( NSString *) title;

{

[[[UIAlertViewalloc] initWithTitle: @ "button test" message: titledelegate: nilcancelButtonTitle: @ "OK" otherButtonTitles: nil, nil] show];

}



@ End



This is 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. tableperformancecount]/3;

Return [self. tableperformancecount] % 3 = 0? Count: count + 1;

}


-(Void) menuDataSource {

[Self. tableDataSourceaddObject: [[MTSMenuModelalloc] init: @ "Job Search" imagePath: @ "jobsearch.png" imagePressPath: @ "jobsearch_press.png" type: JobSearch];

[Self. tableDataSourceaddObject: [[MTSMenuModelalloc] init: @ "Campus recruitment" imagePath: @ "campus.png" imagePressPath: @ "campus_press.png" type: Campus];

[Self. tableDataSourceaddObject: [[MTSMenuModelalloc] init: @ "workplace Info" 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: @ "resume Center" imagePath: @ "resumecenter.png" imagePressPath: @ "resumecenter_focus.png" type: Resumecenter];

[Self. tableDataSource addObject: [[MTSMenuModel alloc] init: @ "salary consulting" imagePath: @ "salaryquery.png" imagePressPath: @ "salaryquery_focus.png" type: Salaryquery];

[Self. tableDataSource addObject: [[MTSMenuModel alloc] init: @ "Application Record" imagePath: @ "jobapply.png" imagePressPath: @ "jobapply_focus.png" type: JobApply];

[Self. tableDataSource addObject: [[MTSMenuModel alloc] init: @ "more" imagePath: @ "themore.png" imagePressPath: @ "themore_focus.png" type: TheMore];

}


@ End





Wpf mvvm mode for third-party controls dev TreeListControl

Blog.csdn.net/..537679.
 
I am a newbie to Diablo 3. I have passed the story model through the past two days. I am grade 70. I don't know what to do.

First, take the risk to brush the box, adjust the equipment, and then fight for the first time, after the third time, after the third time, after graduation, there is no special equipment is rubbish, please play slowly, trial of equipment matching and skill-the characteristics of this game

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.