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 06-15-2008, 05:44 PM   #1 (permalink)
Registered Member
 
Join Date: May 2008
Posts: 133
martinn is an unknown quantity at this point
Default Data lost between tableviews

I have a UINavigationController that contians a UITableView with some UITextFields for the user to input data. When the user clicks on a UIBarButtonItem I save the data in the textfields to an object in my appDelegate that can hold this data. Then I push a new TableView into my UINavigationController. This new TableView uses the data in the object in appDelegate and list it for the user. Now to my problem.

The first time I click UIBarButtonItem to save the data it view the new TableView but in some strange way it doesn't get the data from the textfields. If I then uses the backbutton and then click UIBarButtonItem again the TableView shows up with the right data. I have been trying to figure this out, but can't. What can I be doing wrong?

Please help me out!

The code for saving my textfield-data to the object in appDelegate and push the new viewcontroller:
Code:
Profile *profile = [[Profile alloc] init];
[profile seValue1:textfield1.text];
[profile setValue2:textfield2.text];

TestAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.profile = profile;
[profile release];
		
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[[delegate navigationController] pushViewController: myViewController animated:YES];
[myViewController release];
The code that I use in "MyViewController" in the medhod "cellForRowAtIndexPath" to set the text for a cell:
Code:
cell.text = [delegate.profile value1]
martinn is offline   Reply With Quote
Old 06-15-2008, 06:37 PM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Location: Lexington, KY
Posts: 108
Fastrak is an unknown quantity at this point
Default Re: Data lost between tableviews

How did you specifically declare profile in your app delegate?
Fastrak is offline   Reply With Quote
Old 06-15-2008, 07:12 PM   #3 (permalink)
Registered Member
 
Join Date: May 2008
Posts: 133
martinn is an unknown quantity at this point
Default Re: Data lost between tableviews

In h-file:
Code:
@interface TestAppDelegate : NSObject <UIApplicationDelegate> {
	
	IBOutlet UIWindow *window;
	IBOutlet UINavigationController *navigationController;
	Profile *profile;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
@property (nonatomic, retain) Profile *profile;
In m-file:
Code:
@implementation TestAppDelegate

@synthesize window;
@synthesize navigationController;
@synthesize profile;

...
martinn is offline   Reply With Quote
Old 06-15-2008, 08:45 PM   #4 (permalink)
New Member
 
Join Date: Apr 2008
Location: Lexington, KY
Posts: 108
Fastrak is an unknown quantity at this point
Default Re: Data lost between tableviews

I am thinking you may want to try
Code:
[delegate setProfile: profile];
instead of
Code:
delegate.profile=profile;
(using the setter will force the retain)

Aarom
Fastrak is offline   Reply With Quote
Old 06-16-2008, 04:26 AM   #5 (permalink)
Registered Member
 
Join Date: May 2008
Posts: 133
martinn is an unknown quantity at this point
Default Re: Data lost between tableviews

Thanks Fastrak!

Using setProfile makes it works the first time, but this is a little strange:
In the list with textfields I also have an UISlider and a UISegmentedControl. If I click the UIBarButtonItem the first time the data shows up fine but then I go back and change either the UISlider value or the UISegmentedControl selected item. Then click UIBarButtonItem again and the data is lost. I really don't understand this!

Is there something I'm still missing?
martinn is offline   Reply With Quote
Old 06-16-2008, 11:52 AM   #6 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
scottiphone is on a distinguished road
Default Re: Data lost between tableviews

You can set the debugger to watch your value to see if/when it changes.
Is there any chance something else is over writing it elsewhere?
You also have to make sure if you're dealign with objects that they're correctly retained and not being released somewhere.
scottiphone 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With TableViews CoffeeKid iPhone SDK Development 15 11-10-2008 10:59 AM
pixel data iamdave iPhone SDK Development 2 08-12-2008 08:38 PM
IB for tableviews turinreza iPhone SDK Development 3 07-19-2008 12:43 PM
This seems like a dumb question(about TableViews) jonc iPhone SDK Development 1 04-29-2008 02:12 PM
Transfering data to/from Mac/PC ? jdelgoulet iPhone SDK Development 1 04-29-2008 08:35 AM


» Advertisements
» Online Users: 339
3 members and 336 guests
guusleijsten, Kryckter, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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