简体   繁体   English

MVC iOS-表格视图单元

[英]MVC iOS - tableview cell

I'm a bit confused with MVC pattern in Swift/Obj C . 我对Swift / Obj C中的 MVC模式有些困惑。

Should I put UITableViewCell into View folder and ViewController to Controller folder? 我应该将UITableViewCell放入View文件夹,将ViewController放入Controller文件夹吗?

Short Answer 简短答案

UITableViewCell file : View UITableViewCell文件:查看

UIViewController file : Controller UIViewController文件:控制器

Class file which contains your object data : Model 包含您的对象数据的类文件:模型

Personal Opinion 个人意见

First of all. 首先。 Let's take a quick look on MVC : 让我们快速看一下MVC

Model View Controller or MVC as it is popularly called is made up of the following three parts : 普遍称为Model View Controller或MVC由以下三个部分组成:

Model − Responsible for maintaining data. 模型 -负责维护数据。

View − Responsible for displaying the data to the user. 查看 -负责向用户显示数据。

Controller − Software Code that controls the interactions between the Model and View. 控制器 -控制模型与视图之间交互的软件代码。

For a while i was confused about what is the best place for UITableViewCell file ! 有一段时间我对UITableViewCell文件的最佳位置感到困惑! I have asked my senior, explored blogs and the most important thing was giving my self a minute to think logically and finally i have got the answer. 我问了我的资深,浏览过的博客,最重要的是花一点时间思考一下逻辑,最后我得到了答案。

So my answer is a some kind of sharing knowledge with you and the others from the future. 因此,我的答案是与您和未来的其他人分享知识。

When you are working with a table view, you have a UITableViewCell files, UIViewController file and a class file which contains your data. 使用表视图时,将有一个UITableViewCell文件, UIViewController文件和一个包含数据的类文件 Right ? 对 ?

First things first, u can easily figure out that UIViewController should be in Controller folder and the class file which contains your object data should be in Model folder. 首先,您可以轻松地确定UIViewController应该在Controller文件夹中,而包含对象数据的类文件应该在Model文件夹中。

What about UITableViewCell file ? UITableViewCell文件呢?

This file contains the outlets of your cell which are responsible for displaying the data to user. 该文件包含单元的出口,这些出口负责向用户显示数据。 Simple. 简单。

Good luck :) 祝好运 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM