Ok cool, so the first View Controller is the SchoolSignUpViewController, this where a school user signs up, when they are done, they press the sign up button and I want them to see the SchoolSignUpOnboardingViewController aka nextVC via instantiation.
Here is the function for that desired action I want:
@IBAction func signupPressed(_ sender: UIButton) {
let validationError = validateFields()
let schoolName = schoolNameTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let schoolEmail = schoolEmailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let schoolPassword = schoolPasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let schoolID = schoolIDTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let schoolDistrict = schoolDistrictTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let dateCreated = Date()
if validationError != nil {
return
} else {
//Create user
Auth.auth().createUser(withEmail: schoolEmail, password: schoolPassword) { (result, error) in
guard error == nil else {
self.showAlert(title: "Error Signing Up", message: "There was an error creating the user, please check your connection and try again later.")
return
}
let db = Firestore.firestore()
guard let result = result else { return }
db.document("school_users/\(result.user.uid)").setData(["school_name":schoolName,
"school_id":schoolID,
"remindersPushNotificationsOn": true,
"updatesPushNotificationsOn": true,
"schoolDistrict":schoolDistrict,
"time_created":dateCreated,
"userID": result.user.uid],
merge: true) { (error) in
guard error == nil else {
self.showAlert(title: "Error Signing Up", message: "There was an error creating the user, please check your connection and try again later.")
return
}
}
let changeRequest = result.user.createProfileChangeRequest()
changeRequest.displayName = schoolName
changeRequest.commitChanges { (error) in
guard error == nil else {
return
}
print("School Name Saved!")
}
}
guard let nextVC = storyboard?.instantiateViewController(withIdentifier: Constants.StoryboardIDs.SchoolOnboarding) as? SchoolSignUpOnboardingViewController else { return }
navigationController?.pushViewController(nextVC, animated: true)
}
}
when this is called, this is where the transition from SchoolSignUpVC to SchoolSignUpOnboardingVC is supposed to happen. Instead, what ends up happening is the SchoolSignUpOnboardingVC shows up for literally a split second on screen, and then it vanishes and segues to the SchoolDashboardTableVC.
The transition that does not work as expected is the sign up button, it instantiates the correct view controller yes, but it does for one second and doesn't even allow the user to interact with the screen.
Here is the full code for the SchoolSignUpOnboardingVC :
extension SchoolSignUpOnboardingViewController: PaperOnboardingDataSource {
func onboardingItem(at index: Int) - OnboardingItemInfo {
let next = (UIImage(systemName: "chevron.right.circle")?.mask(with: .white))!
let titleFont = UIFont(name: Constants.AppFonts.menuTitleFont, size: 20) ?? UIFont.boldSystemFont(ofSize: 20)
let descripFont = UIFont(name: Constants.AppFonts.consistentFont, size: 17) ?? UIFont.boldSystemFont(ofSize: 17)
... way too much code for answer
}
func onboardingItemsCount() - Int {
return 7
}
func setupUI() {
let navbar = navigationController?.navigationBar
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = colorLiteral(red: 0.3084011078, green: 0.5618229508, blue: 0, alpha: 1)
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: UIFont(name: Constants.AppFonts.menuTitleFont, size: 22) ?? UIFont.boldSystemFont(ofSize:22)]
appearance.shadowColor = .clear
navbar?.standardAppearance = appearance
navbar?.compactAppearance = appearance
navbar?.scrollEdgeAppearance = appearance
navbar?.prefersLargeTitles = false
navigationItem.setHidesBackButton(true, animated: true)
navigationItem.title = "How Gothere Works"
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "chevron.right.2"), style: .done, target: self, action: #selector(gotoAddAnEventPage))
navigationItem.rightBarButtonItem?.tintColor = .white
}
@objc func gotoAddAnEventPage() {
performSegue(withIdentifier: Constants.Segues.fromSchoolOnboardingToSchoolAddAnEvent, sender: self)
}
}
And then in the actual View Controller file:
class SchoolSignUpOnboardingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
let onboarding = PaperOnboarding()
onboarding.dataSource = self
onboarding.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(onboarding)
for attribute: NSLayoutConstraint.Attribute in [.left, .right, .top, .bottom] {
let constraint = NSLayoutConstraint(item: onboarding,
attribute: attribute,
relatedBy: .equal,
toItem: view,
attribute: attribute,
multiplier: 1,
constant: 0)
view.addConstraint(constraint)
}
}
}
The SchoolDashboardVC has way too many lines of code to post in this thread it wouldn't make sense, the main issue is the transition from SchoolSignUpVC to the SchoolSignUpOnboardingVC.
The Transition should be : SchoolSignUpVC - SchoolSignUpOnboardingVC - SchoolDashboardTableVC
instead it's like : SchoolSignUpVC - SchoolSignUpOnboardingVC (for 1 split second) - SchoolDashboardTableVC.
@Claude31