Iphone global variables available from different angles

Well, that’s why I ultimately want a program in which the user can enter simple data such as their name, date of birth, address, etc., and then this information remains in several views. I have a user entering their information as UITextFields, but there are several types that they use to enter data. Is there a way when a user enters data into a UITextField - then moves to another view - then returns to the original view - that the data will still be in that UITextField? I believe that since there are placeholders, there must be a command to display the previously written text in this field when calling viewController.

Also, in my life I cannot figure out how to keep these variables global. I read in several areas that I should define them in AppDelegate as simple:

NSString *userName;
NSString *userDOB;

But how do I assign strings from UITextFields in another view to these variables and then reassign them to UITextFields when the user returns to the place where they originally entered them?

(Sorry if I don't explain this coherently - I'm a little newbie)

-EDIT- I followed the link below, but still can't figure it out. I tried using:

NSString *name = [[NSUserDefaults standardUserDefaults]objectForKey:@"name"];

[[NSUserDefaults standardUserDefaults] setObject: @ "Horace" forKey: @ "name"];

. ? , say "ViewController1" - - "ViewController1.m"? .

+3
3

question. [NSUserDefaults standardUserDefaults] .

0

NSUserDefaults , , , . , , :

- () viewDidAppear: (BOOL)

:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    MyProjectAppDelegate* appDelegate = (MyProjectAppDelegate*)[[UIApplication sharedApplication] delegate];
    userNameTextField.text = appDelegate.userName;
    userDOBTextField.text = appDelegate.userDOB;
}

, App Delegate.

- , , App Delegate. , , . / , .

+3

, :

  • , , , ?
  • , ?

, , . , . , UITextFields IBOutlet. , , . , . .

, . , , , :

  • , .
  • Core Data, , .
  • You can create application delegate properties. There is a static method in UIApplication that you can call from anywhere to get a link to the delegate.
0
source

Source: https://habr.com/ru/post/1744713/


All Articles