Coder Social home page Coder Social logo

小小的疑问 about mvvmframework HOT 6 OPEN

lovemo avatar lovemo commented on July 24, 2024
小小的疑问

from mvvmframework.

Comments (6)

Alexdara avatar Alexdara commented on July 24, 2024

Model和View不是一一对应的,一个View可对应多个model,换言之将多种结构的数据在一个视图上显示出来

from mvvmframework.

xuguoyongmac avatar xuguoyongmac commented on July 24, 2024

准确的说View不能知道Model的存在,更不能知道Model存在什么属性,您目前的做法肯定是在

  • (void)smk_configureViewWithViewModel:(id)viewModel {

    [viewModel smk_viewModelWithModelBlcok:^(id model) {
    ThirdModel *thirdModel = (ThirdModel *)model;
    self.testLabel.text = thirdModel.title;
    }];
    }
    在这里,已经和明显的用View 直接调用了model,如果我要绑定另外一个Model ,就只有在绑定的时候判断Model的Class然后进行强转再赋值给label。那这个View就没有重用的说法了,如如果我另一个工程需要用到这个View,我要先把这个View拖进去,然后还要拖一个ThirdModel,否则就只能修改代码,这样就无法重用了,所以我个人觉得View 是不能直接调用Model的 ,就是单纯的View,这样才方便单元测试,即使在MVC中,View也不会直接和Model交互,就像 cell.label.text = model.name 这样的语句应该在Controller中,这样才是MVC的真实架构,这也是MVC的C臃肿的其中一个原因。 至少,在这个工程里面,并没有分离出View和Model两者之间的耦合

from mvvmframework.

xuguoyongmac avatar xuguoyongmac commented on July 24, 2024

当然各有各的看法,这里只是存在疑问,就是在MVVM中。类似于cell.label.text = model.name 这样的代码,应该存在什么地方。

from mvvmframework.

Alexdara avatar Alexdara commented on July 24, 2024

model - viewmodel - view 理想情况下view的展示内容绑定到viewmodel,viewmodel初值即界面初值由model提供,复用view实际上需要更改与之匹配的viewmodel(构造函数),如果需要做到纯净的MVVM ,则viewmodel不能有任何复杂的数据类型,最后做出来的view都是标准控件,实际应用我目前只能做到功能内分离,即一个独立功能内部做view-model隔离

from mvvmframework.

LXManMan avatar LXManMan commented on July 24, 2024

代码写的很棒,但是确实view 和model 并没有分离,还是藕断丝连的,view 也做不到复用吧

from mvvmframework.

Akui-Wildhorse avatar Akui-Wildhorse commented on July 24, 2024

为什么不在cell里面去mode化呢

from mvvmframework.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.