Day 2 Curriculum

 

1. Scroll View

  • Create new View Controller
  • Add a scroll view to the superview
  • Add constraints for top, trailing, leading and bottom of scroll view to equal superview
  • Add a view inside the scroll view
  • Add constraints for top, trailing, leading and bottom of view to equal superview
  • Equal width of view to width of view (hold command and select both views, then add width constraint)
  • Add a button within the second view with constraints for top, bottom, and center

 

2. Database

  • For a server, use back4app.com
  • Create account
  • Select 'build a new app'
  • Title app
  • Open App Delegate file on xCode.  In function Application, write:
    • let configuration = ParseClientConfiguration {

      • $0.applicationId = ""

      • $0.clientKey = ""

      • $0.server = "https://parseapi.back4app.com/"

    •         }

              Parse.initialize(with: configuration)

  • import Parse on App Delegate

  • Open dashboard on back4app.com and choose settings.  Within settings, find the applicationID and clientKey

  • Open App Delegate file on xCode.  In function Application, add the ID and Key

3. Text View from Server

  • Create new View Controller
  • Add textField
  • Create new file
  • Connect file to View Controller
  • Import Parse on file
  • Add Outlet for textField
  • Create a custom Class on Back4App Dashboard called "textDetails"
  • Add two columns to the class 
    • curriculumText
    • buttonTag
  • Add a function to load data from parse:

    • func loadData() {

              let query = PFQuery(className: "textDetails")

              query.limit = 1000

              query.whereKey("buttonTag", equalTo: self.buttonTag)

              query.findObjectsInBackground { (objects, error) in

                  if let theObjects = objects {

                      let buttonDetails = theObjects.first

                      self.detailsText.text = buttonDetails?.object(forKey: "curriculumText") as? String

                  }

              }

          }
       

  • Add loadData() to viewDidLoad function

4. IBAction

  • Hold 'control' and drag mouse from a Button on Storyboard to corresponding file
  • Choose Action instead of Outlet
  • Name Action 'buttonPressed'

5. Open New VC with IBAction

  • Add the following inside IBAction func buttonPressed:
    • if let mondayDetailsVC = storyboard?.instantiateViewController(withIdentifier: "mondayDetailsVCIdentifier") as? MondayDetailsViewController {

                  self.navigationController?.pushViewController(mondayDetailsVC, animated: true)

              }

  • Add identifier to storyboard ID of view controller that you want the button to bring you to

6. Connect IBAction to Multiple buttons

  • Hold 'control' and drag mouse from IBAction 'circle' to each button, one at a time

7. Connect buttons to database

  • Add tags to each button (0,1,2,3...)
  • Add the following inside IBAction func buttonPressed:
    • mondayDetailsVC.buttonTag = sender.tag
    • Add it in-between the brackets, just above self.nav...
  • In database, add new rows to the Class textDetails
  • In column 'buttonTag' add tags (0,1,2,3...)
  • In column 'curriculumText' add curriculum text for each button
  • On MondayDetailsViewController add a variable just underneath the outlets
    • var buttonTag = 0

8. Comment Out

  • Place '//' in front of any code and it will comment that code out.

9. Add Images to Scroll View Controller