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?
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.
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.
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:
(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!)