1

I want to present different outlets to the user for different stages of a registration form. For example they enter their first name and last name, press continue and then go onto the next part of the form to enter their date of birth etc and at each stage of the form I want it to be part of a navigation view controller so they can easily press back to go back to the previous part and perhaps change it. Just like how snapchat does when you sign up.

I want only one view controller which will manage all the validation and outlets from the various parts of the form.

I tried creating multiple of the same view controller, and putting different text fields and buttons etc on each page. They were then all embedded in a navigation view controller with segues to each part of the form. The problem with using the same view controller is every time viewDidLoad is called it re-initialises the outlets so ones the user previously entered become nil. I dont want to just save the textfields to a struct for example because the user can press back to go back to this field (and i dont want them to then have to re-enter the information). There must be a simple way to do this?

Also I dont want to create a different view controller for every part because this seems wasteful as not much is displayed on each part

Alex
  • 71
  • 1
  • 6
  • What is the reason to use same view controller? – Harsh Mar 16 '18 at 22:24
  • I thought it seems wasteful since there is little going on, on each view. but i suppose it could be done if its the only way. – Alex Mar 16 '18 at 22:43
  • Stll... That is not a good reason to have the same controller do everything... The more logic that is separated out in different controllers... The better control we have over the architecture of the base. – Harsh Mar 16 '18 at 22:45
  • True. Lets say I had a different view controller for each part of the registration form, there is still the problem of the textfields content being re-initialised every-time a user clicks back and then goes forward again. – Alex Mar 16 '18 at 22:56
  • Yes, to overcome that.. Use Magical PageViewControllers(https://developer.apple.com/documentation/uikit/uipageviewcontroller).. Using pageViewControllers, you will have different view controllers and also maintain the state of it. :) – Harsh Mar 16 '18 at 23:00
  • Im having trouble combining that with a navigation controller. Ive setup the page view controller, implemented the pageViewController functions (for viewControllerAfter & viewControllerBefore) But now I dont get any of the navigation controller functionality. And I embedded the page view controller in a navigation controller. – Alex Mar 17 '18 at 01:20
  • Yep.. because it's not a navigation controller. So you need to write the logic to go back and forth. Remove the navigation controller. It doesn't have any purpose.. – Harsh Mar 17 '18 at 01:21

0 Answers0