我有一个没有 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/