【问题标题】:Pass data from ViewController B to ViewController A [duplicate]将数据从 ViewController B 传递到 ViewController A [重复]
【发布时间】:2013-10-10 19:28:49
【问题描述】:

我之前问过一个关于如何使用 unWind segue 传递数据的问题。但是我认为不可能使用它。

有谁知道如何将数据从 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

【问题讨论】:

    标签: ios objective-c cocoa-touch uiviewcontroller


    【解决方案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];
    }
    

    显然,在 BIDDCCreateViewController 中实现 hereIsTheDoubleThatYouWanted:。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      • 2017-11-08
      • 2021-05-04
      • 1970-01-01
      • 2013-05-01
      • 1970-01-01
      相关资源
      最近更新 更多