子界面
@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];
}