I have made two text fields first is city and second is state and I made two actions of their fields when you clicked in this field you push two new view controller and this controller have name of cities and states when you clicked any cities or states this value passed to main view controller and its text fields display selected value but first I selected city and it shows me name of city in city text field and then I select state show text field to show me value of state in state text field but city text field is empty so how I store value permanent in both text fields.
Asked
Active
Viewed 137 times
-2
-
Save value in preference using NSUserDefaults. – Sapana Ranipa Mar 23 '17 at 10:32
-
but I have an array and not key so how I can use NSUserDefaults? – darsh dixit Mar 23 '17 at 10:36
-
Please read this: https://stackoverflow.com/help/how-to-ask – koen Mar 23 '17 at 11:07
1 Answers
0
To store your array myarray
:
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:myarray forKey:@"arraySaved"];
[userDefaults synchronize];
To get the information back:
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSArray *myarray = [userDefaults objectForKey:@"arraySaved"];

napolux
- 15,574
- 9
- 51
- 70