我希望这个问题不下来投给自己不够具体,因为我认为,这个问题是非常具体(约一般,有时是模糊的概念)。什么是构建用户配置文件的MVC模型,特别是何时在UIViewController和UIView之间进行选择?
当创建用户配置文件,例如,如何严格应当(或可以)MVC模式被遵守,以及什么,如果有的话,对开发这种类型的屏幕的最佳实践,当谈到“控制器”与“观点”?
当我开始在UIViewController中(如下图),我问自己,为什么是的UIViewController绘制资料界面,当我读到的一切MVC说,资料界面是一个视图,不是控制器。该控制器责任,按照我的理解,就像是从模型文件中的包抓取数据和处理的导航处理功能。
的UIViewController
class ProfileViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// set background color
self.view.backgroundColor = UIColor.white
// load banner
banner(profileHasCustomBanner: false)
}
// banner
func banner(profileHasCustomBanner: Bool) {
let bannerHeight: CGFloat = profileHasCustomBanner ? 300 : 150
let bannerImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: bannerHeight))
bannerImageView.image = #imageLiteral(resourceName: "profile-image")
view.contentMode = .scaleAspectFit
view.addSubview(bannerImageView)
}
}
在上面的例子中,UIViewController中中有一个UIView(配置文件的横幅图像)。但是视图应该是一个包含所有屏幕视图的单独文件吗?不过,话又说回来,旗帜依赖于对用户绘制它的接口数据,所以它必须经过控制器,所以旗帜不属于在控制器,对不对?
我要遵守MVC模型尽可能,因此如何在用户配置文件“应该”走近?具体来说,UIViewController应该处理关于用户配置文件的事情,具体是UIView应该处理的是什么?
的UIView
class UserProfileView: UIView {
// do all user profile UIViews go here?
// is this supposed to be a separate file from the file that contains the UIViewController?
}