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 07-07-2010, 08:22 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 31
cliaco is on a distinguished road
Default Passing variables through views

Hi,
I am trying to display 3 views successively with a button in each view, but I loose my value when I call the third one.

In views 2 and 3 I have declared a NSString (key) in the interface, and I set its value in the preceding view just before pushing the view :

- (IBAction)ButtonPressed : (id)sender{

viewController *myView = [[viewController alloc]initWithNibName:nil bundle:nil];

myView .key= key;

myView .modalTransitionStyle =
UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:myView animated:YES];
[myView release];
}

In my 2 view, when loading i have the correct value in key, but when I press the button, the value is "out of scope".

How can i keep my value, so i could pass it to the third view ?

Is ther a better way to do that ?

I thank you for your help

Christophe
cliaco is offline   Reply With Quote
Old 07-07-2010, 08:53 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by cliaco View Post
In my 2 view, when loading i have the correct value in key, but when I press the button, the value is "out of scope".
What do you actually see that tells you it is "out of scope"?
RLScott is offline   Reply With Quote
Old 07-07-2010, 09:03 AM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 31
cliaco is on a distinguished road
Default

Quote:
Originally Posted by RLScott View Post
What do you actually see that tells you it is "out of scope"?
in my second view, in ButtonPress, I set a breakpoint, and "key" is out of scope.
So it is not "passed" to the third view.
cliaco is offline   Reply With Quote
Old 07-07-2010, 09:34 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by cliaco View Post
in my second view, in ButtonPress, I set a breakpoint, and "key" is out of scope.
So it is not "passed" to the third view.
Then post the code that shows how "key" is defined and how you are passing it from one view controller to another. Without all the relevant code posted, it is impossible to say what might be wrong.
RLScott is offline   Reply With Quote
Old 07-07-2010, 10:03 AM   #5 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 31
cliaco is on a distinguished road
Default

Hi,
This is the code.

I have only kept what seems to me to be important. Tell me if you prefer the full code.

key = cleMission

Thanks for your help

Christophe

// detailMissionController.h
#import <UIKit/UIKit.h>

@interface detailMissionController : UIViewController {
NSString *cleMission;
}

@property (nonatomic, copy) NSString *cleMission;


// This is the view3 button
- (IBAction)pointsControleButtonPressed : (id)sender;

@end


// detailMissionController.m

#import "detailMissionController.h"
#import "pointsControleController.h"


@implementation detailMissionController


@synthesize cleMission;


- (IBAction)pointsControleButtonPressed : (id)sender{

pointsControleController *pointControle = [[pointsControleController alloc]initWithNibName:nil bundle:nil];

pointControle.cleMission = cleMission;

pointControle.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController : pointControle animated:YES];
[pointControle release];
}



@end
cliaco is offline   Reply With Quote
Old 07-07-2010, 12:04 PM   #6 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

I assume that cleMission is what is "out of scope" in

Code:
pointControle.cleMission = cleMission;
?

If so, then where is cleMission set? You can't set pointControle.cleMission from cleMission if cleMission is not set first...
RLScott is offline   Reply With Quote
Old 07-07-2010, 12:38 PM   #7 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 31
cliaco is on a distinguished road
Default

Quote:
Originally Posted by RLScott View Post
I assume that cleMission is what is "out of scope" in

Code:
pointControle.cleMission = cleMission;
?

If so, then where is cleMission set? You can't set pointControle.cleMission from cleMission if cleMission is not set first...
Yes, sorry, in the first view I set cleMission like that :

pointControle.cleMission = @"456";
cliaco is offline   Reply With Quote
Old 07-07-2010, 03:48 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by cliaco View Post
Yes, sorry, in the first view I set cleMission like that :

pointControle.cleMission = @"456";
That is not the same cleMission.
RLScott is offline   Reply With Quote
Old 07-08-2010, 07:14 AM   #9 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 31
cliaco is on a distinguished road
Default

Quote:
Originally Posted by RLScott View Post
That is not the same cleMission.
Well, from view1 I can set a variable in view2, is it correct ?

in view1 just before pushing view2, i can do this :

view2 *myView2 = [[view2 alloc]initWithNibName:nil bundle:nil];

myView2.cleMission = cleMission;

So in view2, if cleMission is declared in the interface, I can retrieve the value in cleMission.

Is it correct ?
cliaco is offline   Reply With Quote
Old 07-08-2010, 08:15 AM   #10 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

When you say "cleMission" without any qualifiers, then it refers to either a temporary variable or an instance variable of the class in which the code occurs. Since I did not see any temporary variable of that name in your code, I assume that it refers to an instance variable of the class in which the code resides.

When you say
Code:
pointControle.cleMission = @"456";
you are setting the instance variable of pointControle (using the setter for that variable). And pointControle is itself an instance of the class pointsControleController. (By the way, it is good practice to name your classes starting with an upper case letter and instances of objects starting with a lower case letter.)

The code that you said was giving you the problem was
Code:
pointControle.cleMission = cleMission;
which occurred in the implementation of your detailMissionController class. Therefore the "cleMission" referred to on the right hand side of the equal sign must be the cleMission instance variable of a detailMissionController object. This is certainly not the same thing as the "cleMission" that is being set in
Code:
pointControle.cleMission = @"456";
so that is why I said they are not the same cleMission.

You need to have a clear idea of what an instance variable is. I recommend "Programming in Objective C" by Kochran. It is a very good book, even if you don't know C very well.
RLScott 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: 336
9 members and 327 guests
bignoggins, Chickenrig, firecall, givensur, iNet, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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