问题描述
我正在尝试将数据传递回以前的viewController。
I am trying to pass data BACK TO previous viewController.
有谁知道如何将数据从ViewController B传回ViewController A?所以我想要一个字符串从'BIDAddTypeOfDealViewController转到BIDDCCreateViewController。用户编辑了viewController B,我希望在ViewController A中将编辑后的数据返回到我然后使用它。
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.
我正在使用。
If you are new to objective C, please look at What is Delegate.
在ViewControllerB.h中创建协议:
Create protocol in ViewControllerB.h :
#import <UIKit/UIKit.h>
@protocol senddataProtocol <NSObject>
-(void)sendDataToA:(NSArray *)array; //I am thinking my data is NSArray, you can use another object for store your information.
@end
@interface ViewControllerB : UIViewController
@property(nonatomic,assign)id delegate;
ViewControllerB.m
ViewControllerB.m
@synthesize delegate;
-(void)viewWillDisappear:(BOOL)animated
{
[delegate sendDataToA:yourdata];
}
:当您转到ViewControllerB时
in your ViewControllerA : when you go to ViewControllerB
ViewControllerA *acontollerobject=[[ViewControllerA alloc] initWithNibName:@"ViewControllerA" bundle:nil];
acontollerobject.delegate=self; // protocol listener
[self.navigationController pushViewController:acontollerobject animated:YES];
并定义你的功能:
-(void)sendDataToA:(NSArray *)array
{
// data will come here inside of ViewControllerA
}
已编辑:
您可以看到此示例:如何将数据传回到之前的viewcontroller:
You can See this example : How you can Pass data back to previous viewcontroller: Tutorial link
这篇关于将数据传递回以前的viewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!