Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-17-2011, 10:00 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 8
thoford75 is on a distinguished road
Default Retaining Data when using Storyboards

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?

Cheers!
thoford75 is offline   Reply With Quote
Old 11-17-2011, 12:54 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

save data using userDefaults. Then read the data back in on viewdidload.
RickSDK is offline   Reply With Quote
Old 11-17-2011, 01:02 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 8
thoford75 is on a distinguished road
Default

Quote:
Originally Posted by RickSDK View Post
save data using userDefaults. Then read the data back in on viewdidload.
How can I visually acheive this using storyboards?
thoford75 is offline   Reply With Quote
Old 11-17-2011, 01:13 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

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"

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:@"Blue" forKey:@"House"];

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *houseColor = [userDefaults stringForKey:@"House"];
RickSDK is offline   Reply With Quote
Old 11-17-2011, 08:02 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by RickSDK View Post
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

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-18-2011, 04:15 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 8
thoford75 is on a distinguished road
Default

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.
thoford75 is offline   Reply With Quote
Old 11-21-2011, 06:28 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 8
thoford75 is on a distinguished road
Default

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)

?
thoford75 is offline   Reply With Quote
Old 11-21-2011, 08:13 AM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by thoford75 View Post
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

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-21-2011, 09:47 AM   #9 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 8
thoford75 is on a distinguished road
Default

If it helps here is a screen shot of the storyboard. The segues are all connected as Push
thoford75 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
17 members and 379 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0