Note that there are some explanatory texts on larger screens.

plurals
  1. POPass data back to previous viewcontroller
    text
    copied!<p>I am trying to pass data BACK TO previous viewController. </p> <p>Does anyone know how to pass data back from ViewController B to ViewController A? So I want a string to go 'from' BIDAddTypeOfDealViewController to BIDDCCreateViewController. A user edits viewController B and I want that edited data back in ViewController A where I then use it. </p> <p>I am using the 'passing data back' section of <a href="https://stackoverflow.com/a/9736559/">this answer</a>. How mine differs: Point 3 and 6 just mentions when views are popped so I have put that code in viewWillDisappear. I think that is correct? Also on Point 6 I did not initialise with nib as that is old. I'm using storyboards. And I did not add that last line as I do not believe I would have to push it. Pressing a button on my storyboard already takes me forward. </p> <p>I think the problem may arise in BIDDCCreateViewController, I have the method but I cannot run it. To run a method it should go [self method]. I am unable to do that. Well that is just what I am guessing. </p> <p>It compiles and runs fine just nothing is logged, so I don't know if it works. </p> <p>UPDATE: I am unable to get the 'sendDataToA' method to execute. </p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "BIDAddTypeOfDealViewController.h" @interface BIDDCCreateViewController : UIViewController @property (strong, nonatomic) NSString *placeId; - (IBAction)gotoBViewController:(id)sender; @end #import "BIDDCCreateViewController.h" #import "BIDAddTypeOfDealViewController.h" @implementation BIDDCCreateViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSLog(@"SUCCESSFULLY PASSED PLACE ID: %@", self.placeId); } -(void)sendDataToA:(NSString *)myStringData { NSLog(@"Inside sendDataToA"); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your string Data Showing" message:myStringData delegate:self cancelButtonTitle:@"Ok " otherButtonTitles:nil]; [alert show]; } - (IBAction)gotoBViewController:(id)sender { NSLog(@"pressed"); BIDAddTypeOfDealViewController *bidAddType = [[BIDAddTypeOfDealViewController alloc]init]; bidAddType.delegate = self; } @end @protocol senddataProtocol &lt;NSObject&gt; -(void)sendDataToA:(NSString *)myStringData; @end #import &lt;UIKit/UIKit.h&gt; @interface BIDAddTypeOfDealViewController : UIViewController &lt;UITextFieldDelegate&gt;//Using this delegate for data a user inputs @property(nonatomic,assign)id delegate; //other textfield outlets not relevant - (IBAction)chooseDiscountDeal:(id)sender; @end #import "BIDAddTypeOfDealViewController.h" @interface BIDAddTypeOfDealViewController () @end @implementation BIDAddTypeOfDealViewController @synthesize delegate; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; } -(void)viewWillDisappear:(BOOL)animated { [delegate sendDataToA:@"Apple"]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload