Chapter 24 - Programmatic UIViewController constraints

Good day,

I’m currently playing around with the App Architecture of Chapter 24.

Just wondering why programmatic UIViewController and NSLayoutConstraint.activate doesn’t work?

extension Scene {
      func viewController() -> UIViewController {
        switch self {
        case .books(let viewModel):
          var vc = BookListViewController()
          vc.view.backgroundColor = .white
          vc.bindViewModel(to: viewModel)
          let nc = UINavigationController(rootViewController: vc)
          return nc

I’ve tried activating the constraints in viewDidLoad and viewDidLayoutSubviews, but for some reason the controls all end up underneath the UINavigationBar?

Why would this happen?

@fpillet Can you please help with this when you get a chance? Thank you - much appreciated! :]

@martinjbt I think this is unrelated to RxSwift or MVVM. I’m not sure how you have setup your constraints (you don’t show anything here), but you don’t provide enough information here for us to determine whether there could be some intereference from this Scene mechanism.

The only thing that comes to mind would be that you may have been doing something during the bindViewModel phase that could have had an impact.

@fpillet Thank you for the reply. This was my own mistake. Late night with tired eyes not being able to spot the mistake in my constraints :slight_smile:

Thank you for the amazing book!

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.