Two ways to Thin CONTROLELR code in IOS

Source: Internet
Author: User

MVC is the iOS app architecture recommended by Apple. Later, MVVM,MVP and other architectures emerged. The main purpose is to decouple the business logic, presentation, and data levels. Achieve maximum code reuse.

For the MVC architecture, with the increase in the number of modules in the app, the business logic in the controller becomes more and more complex and the amount of code is increasing. A file with thousands of rows is also common. This is a time-consuming thing to do even with Mark's search method.

In this case, we can separate unnecessary code, such as the construction of the view and its child controls, the Uitableview,uicollectionview DataSource method can be a separate class.

1, the view layer can be built into a sub-level to achieve. You can also use the interface + message forwarding second step (forwardtarget:forselector:) to achieve.

2, DataSource method can be used in the third step of message forwarding, forwardinvocation: the implementation of the method is transferred to another class. Why is the Uitableviewdelegate method not also implemented by other methods?

In fact, it is also possible, but Uitableviewdelegate has a click event, preferably put into the controller to achieve, this event response is best done by the controller.

Demo

Https://github.com/wjwdive/BindViewTest

Two ways to Thin CONTROLELR code in IOS

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.