2013-10-10 91 views
-2

我問了一個關於如何使用unWind segue傳遞數據的問題。但我認爲這是不可能的。從ViewController B傳遞數據到ViewController A

有誰知道如何將數據從ViewController B傳回ViewController A?在我的代碼中,我想要數據,讓我們說一個雙重的傳遞。所以我想要一個雙從'BIDAddTypeOfDealViewController'到BIDDCCreateViewController。

就這樣我清楚,因爲上次有混亂。用戶編輯viewController B,然後我想將編輯後的數據放回到ViewController A中,然後使用它。

我嘗試過多個例子,但仍然無法做到這一點。我花了好幾天的時間嘗試仍然沒有成功。

任何幫助,非常感謝。

#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 

回答

-1

使用代表團。

在BIDAddTypeOfDealViewController

@property (nonatomic, unsafe_unretained) id delegate; 

當您創建BIDAddTypeOfDealViewController的一個實例,設置BIDDCCreateViewController作爲其委託添加的屬性。

後來在:

-(void) chooseDiscountDeal:(id)sender 
{ 

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

,顯然,實施hereIsTheDoubleThatYouWanted:在BIDDCCreateViewController。

相關問題