Search code examples
xcodexcode6storyboarduistoryboardseguexcode-storyboard

Storyboards segues and back


I have two ViewControllers connected by a segue:
The first one has many TEXT FIELDs for user input and some LABELS to perform calculations. There is a button (storyboard segue) which send the user to the second Storyboard which has some pictures, in this second ViewController there is a button (storyboard segue) to bring back to the first ViewController. When the user go back to the first ViewController all TEXT FIELDS/LABELs are blank.
The user will need to use the data in the first VC as many times he needs to go from VC1 to VC2 and back.
There is a button which will CLEAR ALL data when user wants perform another session, There is no need to keep the data after the app is closed.
Any help is more than welcome.


Solution

  • I think you can create a class to keep the data in global session.

    class Session:NSObject {
        static var textfieldA = ""
        ...
    
        class func clearAll() {
            Session().textfieldA = ""
            ...
        }
    }
    
    // In VC1
    // to set string
    Session().textfieldA = "abc"
    // to get string
    anystring = Session().textfieldA
    // to clear all
    Session().clearAll()