iphone - 在这种情况下,MVC 最佳实践是什么?

标签 iphone objective-c ios ipad model-view-controller

我有一个没有 Nib 的 View Controller 。我在代码中创建 View 。我在viewDidLoad

中一直这样做
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 475, 50.0)];
self.headerView = header;
self.headerView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:self.headerView];

UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height - 50.0, 475, 50.0)];
self.footerView = footer;
self.footerView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
self.footerView.backgroundColor = [UIColor greenColor];
[self.view addSubview:self.footerView];

等等。但是,随着我的 viewDidLoad 变得越来越长,我觉得这可能不应该在我的 Controller 中。这真的应该是一个子类化的 UIView,然后加载到我的 viewDidLoad 中吗?对于这种情况,MVC 最佳实践是什么?

最佳答案

Should this really be a subclassed UIView that is then loaded in my viewDidLoad?

在我看来:是的。我可能会有一个用于 Controller View 的类,它会创建页眉和页脚 View (它们本身可以从 UIView 继承)。

What is the MVC best practice for this kind of situation?

这些 View 和 subview 都是MVC的“V”部分。我越想越觉得,你现在有东西, Controller 在做一些“V”的工作。我并不是说这一定不好,但随着 View 创建代码变得更大,您当然应该考虑更好的分离。

关于iphone - 在这种情况下,MVC 最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10282226/

相关文章:

iphone - iOS 10.0 Beta,键盘扩展 : The disappearing number pad (iPhone)

ios - Swift 键盘不会被 touchesBegan 关闭

iphone - 我必须提供哪些选项才能提供允许对 UITableView 进行排序的功能?

ios - UIPickerView 不加载行

ios - 带有 ScrollView 的 ViewController 显示空屏幕

iphone - XCode 7.3 ScrollView 和导航 Controller

ios - 每次 Plist 文件都会被覆盖

ios - 当多个对象在iOS中调用函数时,如何等待函数完全执行?

iphone - 如何更新激活推送通知的应用程序

iphone - 初学者 : Multiview app doesn't switch views correctly