模型视图控制器 (MVC) - 实际实施帮助

发布于 2024-09-28 02:29:46 字数 706 浏览 5 评论 0原文

在几周的时间里,我断断续续地工作,成功地创建了我设想的应用程序。有我想要的功能,而且性能也不算太差。然而,如果我看一下我的代码,它显然是在没有适当 MVC 考虑的情况下组合在一起的,而且我知道如果我尝试扩展应用程序或为其他应用程序重用东西,它会咬我的屁股。

我希望得到的帮助是帮助我了解应用代码的每个部分应该放置在哪里。

这是我得到的文件:
1. 应用程序委托 - NSObject(假设模型?)
2.视图控制器-UIViewController(假设控制器?)
3.视图 - UIView(假设视图?)

以下是我实现的一些东西:
1. 设置实例变量的初始值。
2. 目标操作(IBOutlet、IBAction)(例如按下按钮来调用方法)
3.将相册中的图片加载到UIImage
4. 将UIImage保存到相册中(即UIImageWriteToSavedPhotosAlbum)
5. 确定运行硬件的最大图像分辨率的方法。
6.绘制渐变(例如CGContextDrawLinearGradient)
7. 调整图像大小。
8.显示图像(如drawInRect)
9. 处理内存警告。
10.切换UI控件可见性的方法
11. 线程方法

上面的大部分内容都在我的视图中,我认为这是完全错误的。请帮我将上面列出的 11 项映射到应将它们放置在哪个文件或 MVC 中。

谢谢!

In a couple of weeks, working on and off, I've managed to create the app that I had envisaged. It has the functions I want, and the performance is not too bad. However, if I look at my code it clearly has been put together without proper MVC consideration, and I know it's gonna bite me in the butt if I try scale the app or reuse stuff for other apps.

The assistance I would appreciate is to help me understand where each of the bits of my app code should be placed.

Here are the files I've got:
1. App delegate - NSObject (Assume Model?)
2. View Controller - UIViewController (Assume Controller?)
3. View - UIView (Assume View?)

Here are the kinds of things I've implemented:
1. Set initial values for instance variables.
2. Target-Action (IBOutlet, IBAction) (e.g. Button pressed to call a Method)
3. Load an image from Photo Album into UIImage
4. Save a UIImage into Photo Album (i.e. UIImageWriteToSavedPhotosAlbum)
5. Method to determine the maximum image res for the hardware it's running on.
6. Drawing gradients (e.g. CGContextDrawLinearGradient)
7. Resizing of images.
8. Display the image (e.g. drawInRect)
9. Deal with memory warnings.
10. Method to toggle UI controls visibility
11. Threaded methods

Most the the above is within my View which I imagine is completely wrong. Please help me map the 11 items list above to which file or MVC they should be placed in.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2024-10-05 02:29:46

回顾我的这个问题,难怪没有回应……因为它非常广泛,如果我问一些单独的小问题会更好。

不管怎样,自从问这个问题以来,我一直在做更多的研究。简而言之,从设计模式的角度来看,我所做的事情似乎非常错误。需要大量的返工才能把事情做好。

对于那些有 MVC 设计模式查询的人,我发现这个问题/答案线程非常有用 - 此处

谢谢。

Looking back this question of mine, it's no wonder there are no responses... as it is extremely broad, and would have been better if I had asked a number of separate small pointed questioned instead.

Anyhow, since asking this question I've been doing some more research. It seems that in a nutshell I've been doing things terribly wrong from a design pattern point-of-view. It's gonna take quite a bit of re-work to get things done right.

For those that have MVC design pattern queries, I found this SO question/answer thread very useful - here.

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文