iOS MVVM Practice Refreshing network requests +tableview presentation data

Source: Internet
Author: User

The following is the first demonstration of implementation:

This example shows the form of an MVVM structure, expressed as follows

M: The data model is stored and can be used to process attributes. (that is, the Fat model concept, in XX million people subscribe to this processing method written in model)

V:view. Used to unify the management of control initialization and layout.

Vm:viewmodel. Responsible for network requests and other calculations or event handling

The directory structure is as follows:

The Viewcontroller folder has a controller and a mldataview, This view is added to the controller Self.view, and then the initialization, addition and layout of the other view in this controller is done in this mldataview, which integrates the view separation.

Mldataviewmodel is responsible for the network request, the implementation of the TableView proxy and the data source method, and the encapsulation of some other event logic. Traditional MVC typically puts this code in the controller, which reduces the controller's code a lot now.

The Mldatamodel stores the transmitted data, which can also be used to process some formatted data. Such as

This model can also share the formatting of some attributes.

Some other packages on the overall architecture:

1. Custom Mlhttpsessionmanager inherits from Afhttpsessionmanager, can gracefully handle the request header, the response header or the HTTPS setting related information in the custom class

2. Network Request Extensibility Strong: The company's network request implementation of the file logic much more, including token invalidation, refresh Refreshtoken, network request error code interception and so on. These businesses can be joined according to their own needs.

3.MLCustomHud popup toast prompt. Practicality is very strong.

4.Base folder There are two classes, in fact, enterprises and projects basically will establish a base class, that is, so view can have a base class, such as Tableview,uilabel,uibutton,wkwebview,uitableviewcell, etc. You can then establish some shortcut methods in the base class to set properties, and so on.

The code in Unicode in the 5.Category folder is not able to output Chinese in order to implement NSLog.

6.Category Uiview+hudcount classification, using runtime to reference the view count. Its unique advantage is to prevent multiple network requests at the same time when the loading box interference, you can prevent the loading box overlap or disappear prematurely.

Finally attach the demo address:

Code Cloud: Https://gitee.com/LiJinShi/MVVM_Demo

Github:https://github.com/lijinshi/mvvm_demo

iOS MVVM Practice Refreshing network requests +tableview presentation data

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.