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 02-03-2012, 07:19 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 8
JackSac67 is on a distinguished road
Exclamation How do I use properties defined in one class in another?

OK, so in an app I'm making, there is a UIPicker that assembles a sentence by individual words you pick with the picker. When you make the desired sentence, you press a go button and it brings you to a new a view where the string is displayed on the new view. The string is made with an NSString property *passedString, and since its being displayed in the second view, its declared in the second view class. However, the method to make the string is in the first view class, as that view is where the go button is. So my question is, how can I get the string that is being created with the picker to be stored in the *passedString NSString property I defined in my second view class?
JackSac67 is offline   Reply With Quote
Old 02-03-2012, 08:58 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

Code:
NSString *theString = nil;

/* Put string together however your app does so */

SecondViewController *secondViewContr = [[SecondViewController alloc] init];
secondViewContr.passedString = [NSString stringWithString:theString];

/* Switch to secondViewContr here however your app does so */
Something like that?
__________________
HEY! Was this post helpful?
If so, it would be MUCH appreciated if you'd just click on one of these apps:



MyD
Take 1 minute to set up your MyD and you'll always be able to prove you own your device!

Membrik
Test your memory by sliding tiles to match chains of increasing difficulty.

©2011 Dardom Productions | Like us on Facebook!
SoulRed12 is offline   Reply With Quote
Old 02-03-2012, 09:00 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 280
dapis is on a distinguished road
Default

Your question has been asked and answered numerous times on this forum, just do a search for the relevant terms and you'll get plenty of detailed answers.
dapis is offline   Reply With Quote
Old 02-04-2012, 11:10 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 8
JackSac67 is on a distinguished road
Default

Quote:
Originally Posted by SoulRed12 View Post
Code:
NSString *theString = nil;

/* Put string together however your app does so */

SecondViewController *secondViewContr = [[SecondViewController alloc] init];
secondViewContr.passedString = [NSString stringWithString:theString];

/* Switch to secondViewContr here however your app does so */
Something like that?
yeah I figured it out. Thanks anyway! Here is what I did:
Code:
- (IBAction)makeMessage:(id)sender {
    
    secondView *second = [[secondView alloc] initWithNibName:nil bundle:nil];
    self.secondViewData = second;
    [self presentModalViewController:second animated:YES];
    
    secondViewData.passedString = [NSString stringWithFormat:@"%@ %@ %@ %@!",
                            textField_.text ? textField_.text:@"",
                            [adjective_ objectAtIndex:[messager_ selectedRowInComponent:0]],
                            [verb_ objectAtIndex:[messager_ selectedRowInComponent:1]],
                            [noun_ objectAtIndex:[messager_ selectedRowInComponent:2]]];
    NSLog(@"%@", secondViewData.passedString);

}
(secondViewData is the instance of secondView I defined in my main ViewController class. I also added in a UITextField so the user can add their own beginning to the sentence!)
JackSac67 is offline   Reply With Quote
Reply

Bookmarks

Tags
classes, nsstring, properties, uipicker

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: 395
18 members and 377 guests
Apptronics RBC, Atatator, chiataytuday, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, kukat, LunarMoon, MAMN84, n00b, pbart, reficul, Retouchable, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,124
Posts: 402,909
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:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0