Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I have 8 detail view controllers and 1 main controller in a storyboard setup.
The main controller features a table with 8 rows which link (push) to each relevant module controller.
If I make a change on a module controller page then use the navigation (back) to return to the main controller and then try to go back into that page via the table links, the data resets.
How can I setup the storyboard so that data saves in-between navigation?
its hard to tell exactly what you are trying to do, but you mentioned that the data "resets".
If order to not get data to "reset", you need to read that data in from userDefaults rather than reading it in from the initial view controller data.
For example if you go to a view controller and it defaults to a "red house" and then the user can change it to a "blue house" withint the controller, you need to save that blue data and when you reload the view, find out what color it is supposed to be by reading in the data from userDefaults, rather than defaulting to "red"
its hard to tell exactly what you are trying to do, but you mentioned that the data "resets".
If order to not get data to "reset", you need to read that data in from userDefaults rather than reading it in from the initial view controller data.
Bollocks.
You could use user defaults to save the state, but you don't have to do it that way.
In fact, using user defaults is an ill-fitting approach to the problem of saving state in memory. User defaults writes files to disk, which is much slower, and causes the state save to persist even if you exit the app. (yes, it's much slower even in iOS, where the "disk" is really flash memory.)
If you want the state to persist after exiting and re-launching then saving it to user defaults is a reasonable approach.
If you're only saving state information for the case where a user switches from one view to another and back, it would be much better to use a data container singleton to save the state data there. (See the link to the password generator in my signature for an example of a data container singleton.)
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
Ideally what I am trying to build is a multipage form.
1st Page - List of 8 Rooms - linking to 8 individual view controllers
each 8 view controllers contains text fields that need to be saved. For example if the user selects from the 1st page 'Bedroom', fills in some text fields, then returns to the home page, selects 'Bathroom', fills in some text fields, the text fields in 'Bedroom' should remain either until a) the user clicks a button to email the information for all 8 rooms or b) closes the app.
Just a thought...but could it be todo with the use of the segue?
I know if I pushed navigation from 1 to 2 to 3 to 4 and so on, the data would be save if I clicked back from 4 to 3.
However sometimes I may want to go from 4 back to 1 (main screen) then back to 4 again and the data will reset (text box's to zero)
?
It has to do with the way Storyboard works. I'm still trying to figure this out. It seems that storyboard always releases a view controller when you leave it, and always creates and initializes a new copy of the view controller you are switching to.
I want to understand how you set up your program so storyboard switches between persistent instances of your view controllers. It does not seem like it 's set up to do that.
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIf order to not get data to "reset", you need to read that data in from userDefaults rather than reading it in from the initial view controller data.
For example if you go to a view controller and it defaults to a "red house" and then the user can change it to a "blue house" withint the controller, you need to save that blue data and when you reload the view, find out what color it is supposed to be by reading in the data from userDefaults, rather than defaulting to "red"
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:@"Blue" forKey:@"House"];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *houseColor = [userDefaults stringForKey:@"House"];
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou could use user defaults to save the state, but you don't have to do it that way.
In fact, using user defaults is an ill-fitting approach to the problem of saving state in memory. User defaults writes files to disk, which is much slower, and causes the state save to persist even if you exit the app. (yes, it's much slower even in iOS, where the "disk" is really flash memory.)
If you want the state to persist after exiting and re-launching then saving it to user defaults is a reasonable approach.
If you're only saving state information for the case where a user switches from one view to another and back, it would be much better to use a data container singleton to save the state data there. (See the link to the password generator in my signature for an example of a data container singleton.)
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome1st Page - List of 8 Rooms - linking to 8 individual view controllers
each 8 view controllers contains text fields that need to be saved. For example if the user selects from the 1st page 'Bedroom', fills in some text fields, then returns to the home page, selects 'Bathroom', fills in some text fields, the text fields in 'Bedroom' should remain either until a) the user clicks a button to email the information for all 8 rooms or b) closes the app.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI know if I pushed navigation from 1 to 2 to 3 to 4 and so on, the data would be save if I clicked back from 4 to 3.
However sometimes I may want to go from 4 back to 1 (main screen) then back to 4 again and the data will reset (text box's to zero)
?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI want to understand how you set up your program so storyboard switches between persistent instances of your view controllers. It does not seem like it 's set up to do that.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome