-2

I asked a question on how to pass data using unWind segue before. However I do not think it is possible to use this.

Does anyone know how to pass data back from ViewController B to ViewController A? In my code I want data, lets say a double to be passed back. So I want a double to go 'from' BIDAddTypeOfDealViewController to BIDDCCreateViewController.

Just so I am clear as there was confusion last time. A user edits viewController B and I want that edited data back in ViewController A where I then use it.

I have tried multiple examples and still haven't been able to do it. I have spent days now trying still with no success.

Any help is greatly appreciated.

#import <UIKit/UIKit.h>

@interface BIDDCCreateViewController : UIViewController
@property (strong, nonatomic) NSString *placeId;


@end


#import "BIDDCCreateViewController.h"

@implementation BIDDCCreateViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"SUCCESSFULLY PASSED PLACE ID: %@", self.placeId);

}



@end
#import <UIKit/UIKit.h>


@interface BIDAddTypeOfDealViewController : UIViewController <UITextFieldDelegate>

- (IBAction)chooseDiscountDeal:(id)sender;
@end


#import "BIDAddTypeOfDealViewController.h"
#import "BIDDCCreateViewController.h"

@interface BIDAddTypeOfDealViewController ()

@end

@implementation BIDAddTypeOfDealViewController

-(void) chooseDiscountDeal:(id)sender
{
    //pass back double
}
@end
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Anthony
  • 879
  • 3
  • 11
  • 17

1 Answers1

-1

Use delegation.

add a property in BIDAddTypeOfDealViewController

@property (nonatomic, unsafe_unretained) id delegate;

when you create an instance of BIDAddTypeOfDealViewController, set BIDDCCreateViewController as its delegate.

Later in:

-(void) chooseDiscountDeal:(id)sender
{

//get your double from sender or however
[self.delegate hereIsTheDoubleThatYouWanted:double];
}

and obviously, implement hereIsTheDoubleThatYouWanted: in BIDDCCreateViewController.

ManicMonkOnMac
  • 1,476
  • 13
  • 21