-5

I'm stuck with the following:

  • There are two view controllers, viewController1 and viewController2.

  • In viewController1, a UIButton, UITextField are created programmatically in viewDidLoad, and the button views viewController2 when pressed.

Is there a way for viewController2 to fetch data from the UITextField in viewController1 when it shows up.

Thank you..

Kenan Karakecili
  • 731
  • 6
  • 23
  • 2
    This SO meta answer I follow and I think you (user3340000) should too: "How much research effort is expected of Stack Overflow users?" http://meta.stackexchange.com/questions/182266/how-much-research-effort-is-expected-of-stack-overflow-users/182380#182380 – nzs Feb 28 '14 at 10:30
  • 1
    I have learned a great deal a stack overflow and I'm ever grateful for the help this site has offered me. But I fear the treatment of this poor user on his first ever question is quite poor, he is immediately alienated and belittled. Is it so difficult to throw a new guy a bone people? – Jef Feb 28 '14 at 11:30

1 Answers1

0

There is a way (or many ways) to do just about anything :)

however I suspect it will be far simpler in your example to set the string from the textField in viewController1 to a property or indeed some method you put there (in viewController2) like

-(void)prepareToPresentHereIsYourStringFromMyTextField:(NSString *)textFieldContent;

the reason this will be far simpler is that viewController1 will already have imported the header file for viewController2, so it will immediately 'see' this selector and be able to call it, and viewController1 will already have a pointer to viewController2 immediately before it is presented. It can be done the other way around like you asked, with viewController2 'fetching' or 'getting' this string from viewController1, but it would be a little more fiddly, viewController2 would need to know something about viewController1, whether it import the entire header or you implement a tiny protocol, and it will need to be given a pointer to viewController1 to call on..

Jef
  • 4,728
  • 2
  • 25
  • 33
  • 2
    I didn't downvote it, but I find this a pretty poor answer. There is a lot of text to explain a simple feature of passing data as a param. The longest method name i've ever seen and no actual code to show it being done – Simon McLoughlin Feb 28 '14 at 10:43
  • thanks @SimonMcLoughlin, you're certainly entitled to an opinion. The majority of the text is explaining WHY its simpler to set in this case than get. Basics perhaps. As for an implementation, well fair enough I guess, the asker wants a NSString from UITextField in presentingViewController, presumably he has some intent for this NSString which is beyond the scope of the question. I think it is interesting that you feel I used too much text to explain such a simple feature of passing data, yet on the other hand you want an example implementation. – Jef Feb 28 '14 at 11:13