How to make custom controller for View in iOS

Issue #318

I do UI in code, and usually separate between View and ViewController.

1
2
3
4
5
6
7
class ProfileView: UIView {}

class ProfileViewController: UIViewController {
override func loadView() {
self.view = ProfileView()
}
}

But in places where using UIViewController and manage their view controller containment hierarchy is not desired, then we can roll out a normal object to act as the controller.

1
2
3
4
5
6
7
8
9
10
11
class ProfileController {
let profileView: ProfileView

init(profileView: ProfileView) {
self.profileView = profileView
}

func update(profile: Profile) {
profileView.nameLabel.text = profile.name
}
}

If the name Controller sounds confusing with UIViewController, I usually use Handler, which contains other Handler to handle logic for view

Comments