浅谈MVVM框架
来源:互联网 发布:dnf网络连接中断tgp 编辑:程序博客网 时间:2024/06/16 09:58
MVC简介
Model——即模型。模型一般都有很好的可复用性,统一管理一些我们需要使用的数据。
View——就是存放视图使用的。
Controller——控制器它负责处理View和Model的事件。
MVVM简介
#import <Foundation/Foundation.h>
@interface User : NSObject
@property (nonatomic,copy)NSString *userName;
@property (nonatomic,assign)NSInteger userId;
@end
#import "User.h"
@implementation User
- (id)init{
self = [superinit];
if (self) {
self.userName =@"";
self.userId = 20;
}
returnself;
}
@end
#import <Foundation/Foundation.h>
@class User;
@interface UserViewModel : NSObject
@property (nonatomic,strong)User *user;
@property (nonatomic,strong)NSString *userName;
@end
#import "UserViewModel.h"
#import "User.h"
@implementation UserViewModel
- (id)init{
self = [superinit];
if (self) {
//在这里处理业务逻辑
_user = [[Useralloc]init];
if (_user.userName.length > 0) {
_userName =_user.userName;
}else {
_userName = [NSStringstringWithFormat:@"简书%ld", (long)_user.userId];
}
}
returnself;
}
@end
ViewController.m文件
#import "ViewController.h"
#import "UserViewModel.h"
@interface ViewController ()
@property (nonatomic,strong)UILabel *userLabel;
@property (nonatomic,strong)UserViewModel *userViewModel;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
_userLabel = [[UILabelalloc]initWithFrame:CGRectMake(10, 199, 200, 50)];
_userLabel.backgroundColor = [UIColorredColor];
_userViewModel = [[UserViewModelalloc]init];
_userLabel.text =_userViewModel.userName;//显示
[self.viewaddSubview:_userLabel];
// Do any additional setup after loading the view, typically from a nib.
}
- 浅谈MVVM框架
- 浅谈Android MVVM 框架模式
- 浅谈MVVM MVC MVP框架
- 浅谈mvc、mvp、mvvm框架模式
- MVVM框架
- MVVM框架
- MVVM模式浅谈
- 浅谈WPF中的MVVM
- 浅谈MVVM软件架构
- 浅谈 MVC MVP MVVM
- 浅谈MVC、MVP、 MVVM
- Android MVP MVVM浅谈
- iOS 浅谈MVVM+RAC
- 浅谈MVC,MVP和MVVM三个的安卓常用框架
- mvvm 框架 比较
- MVVM框架 v1发布
- WPF MVVM框架(转)
- MVVM框架介绍
- package.json详解
- linux网络编程和快速理解epoll
- Ubuntu更改服务源
- Java中的四种运算符
- 第一个spark程序
- 浅谈MVVM框架
- 六度分离 HDU 1869
- cortex-M3 异常-- SVC、PendSV介绍
- 选择机器学习的原因
- windows通过命令行打开任意程序
- 理解 Python 装饰器就看这一篇
- Socket长连接和短连接的区别
- I/O多路复用
- Java异常处理