-1

So ultra NOOB when it comes to iPhone development

I have three view controllers for a Tab Bar Controller. What I want here is when I press a button the data from TextFields in the first view get fetched and displayed.

In my firstViewController.h I have declared the TextFields like this:

IBOutlet UITextField * driver;
IBOutlet UITextField * phone;
IBOutlet UITextField * poe;
IBOutlet UITextField * doe;
IBOutlet UITextField * coe;
IBOutlet UITextField * dod;
IBOutlet UITextField * customer;
IBOutlet UITextField * customerContact;
IBOutlet UITextField * customerTank;
IBOutlet UITextField * trailer;
IBOutlet UITextField * truck; 

Then in my Main.storyboard I have connected the outlets to each TextField

Now I thought that it just was to import the firstViewController.h to my thirdViewController.h using the #import "" and somehow check when button click was trigged. But it does not seems to be that easy in terms of NOOBines.

I thought that doing something like this in the thirdViewController.h could make the magic:

#import <UIKit/UIKit.h>
#import "FirstViewController.h"
@interface ThirdViewController : UIViewController{
NSString *theDriver = [driver.text];
}
@end
rmaddy
  • 314,917
  • 42
  • 532
  • 579
codemoonger
  • 613
  • 3
  • 11
  • 22
  • I had this problem a while ago. You can look at this solution [here](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Kyle Griffith Feb 29 '16 at 15:47
  • maybe this is helpful http://stackoverflow.com/questions/32979924/passing-data-from-the-firstviewcontroller-to-the-lastviewcontroller/32980270#32980270 – vikingosegundo Feb 29 '16 at 19:04

1 Answers1

1

unfortunately it isnt that easy. assuming there is a secondViewController in between your first and third, you're going to pass variables through during the segue using this method. define some variables in the .h file of your second view controller like driver, phone, etc. and assign those values from what you have right there

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        if ([segue.identifier isEqualToString:@"the name of your segue"]) {
            secondViewController *secondVC = segue.destinationViewController;
            secondVC.driver = self.driver.text;
            secondVC.phone = self.phone.text;
           //continue typing your values and use this to carry this same method in your secondViewController to carry them into your thirdViewController
}

EDIT 1:

Here is an example I used in an app of mine where I am looking at a list of games and I want to look at one individual game. This is the code in the MatchesViewController.m file. I have my gameObject (in your case the gameObject would be text) and I want to send it to the next view controller. I have also have this imported in the "MatchesViewController.m"

#import "EachMatchViewController.h"


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showOneGame"]) {
        EachMatchViewController *eachVC = segue.destinationViewController;
        eachVC.gameObject = self.gameObject;
    }
}

This is what is defined in my "EachMatchViewController.h" which is the view controller I am going to.

@property (strong, nonatomic) PFObject *gameObject;

some in my "EachMatchViewController.m" I can use it the data that is being passed over.

kygcoleman
  • 734
  • 15
  • 25
  • The code you provide here is added to the FirstViewController.m file and the problem now is it can't find the segue.SecondViewController. Do need to create something extra or should it pop up? – codemoonger Feb 29 '16 at 18:29
  • It is suppose to be segue.destinationViewController regardless of where you're going. If you're using a storyboard with segues you'll have to give the segue a name which is where you're checking the segue.identifier. If you're not using a storyboard I would check out the comment under the your question. There's a bunch of great stuff in there. – kygcoleman Feb 29 '16 at 18:33
  • I saw that. I don't seem to be able to access the declared IBOutlet UITextField *driver; in the SecondViewController.h and it don't seems to find it. Saying that "Property 'driver' not found on object of type 'SecondViewController *' did you mean to access instance variable 'driver'?" – codemoonger Feb 29 '16 at 18:45
  • check out the editted part of my answer and see if that makes things any clearer. @alexandermogren – kygcoleman Feb 29 '16 at 19:02
  • Thanks a lot, give me a lot of minus for this post because i give up. Cant wrap my head around it, i must be braindead. – codemoonger Feb 29 '16 at 21:03