MVVM简单使用

经常听说MVVM,不知道是啥,学习了下,理论知识网上一堆,还是会用就好,废话不多说,直接上代码

Model.h

@property(nonatomic,strong)NSString*name;

@property(nonatomic,strong)NSString*tittle;

modelView.h

#import

#import"MyModel.h"

@interfaceMyViewModel :NSObject

@property(nonatomic,strong)NSString*nameStr;

@property(nonatomic,strong)NSString*tittleStr;

@property(nonatomic,strong)MyModel*useModel;

- (instancetype)initWithModel:(MyModel*)model;

modelView.m

- (instancetype)initWithModel:(MyModel*)model

{

   if([superinit]) {

       self.useModel= model;

        [selfbinData];

//        if (model.name.length > 0) {

//            _nameStr =model.name;

//        } else {

//            _nameStr = @"暂无数据";

//        }

    }

   returnself;

}

- (void)binData

{

   self.nameStr=self.useModel.name;

   self.tittleStr=self.useModel.tittle;

   if(self.nameStr>0) {

        _nameStr=@"暂无数据";

    }else{

    }

   if(self.tittleStr>0) {

    }else{

       _tittleStr=@"MVVM练习";

    }

}


你可能感兴趣的:(MVVM简单使用)