从子界面获取数据返回给主界面

来源:互联网 发布:淘宝客推广有什么要求 编辑:程序博客网 时间:2024/06/05 08:33

子界面

@protocol getLabelDelegate <NSObject>- (void)getNString:(NSString *)str;@end@interface AddViewController : UIViewController@property (weak, nonatomic) id <getLabelDelegate> delegate;@end

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view from its nib.    UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(finish)];    self.navigationItem.rightBarButtonItem = rightBtnItem;}-(void) finish{    [self.delegate getNString:@"abc"];    [self.navigationController popViewControllerAnimated:YES];}

主界面

@interface MyViewController : UIViewController<getLabelDelegate>@property (weak, nonatomic) id<getLabelDelegate> delegate;@end

@implementation MyViewController{//    NSMutableArray *myArray;    NSMutableArray *testArr;}- (void)getNString:(NSString *)str{    [testArr addObject:[[NSString alloc] initWithString:str]];}

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view from its nib.        UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];    self.navigationItem.rightBarButtonItem = rightBtnItem;}-(void)add{    AddViewController *addvc = [[AddViewController alloc] init];    addvc.delegate = self;    [self.navigationController pushViewController:addvc animated:YES];}


0 0
原创粉丝点击