you have to create custom delegate
in CViewController.h
@protocol SecondViewControllerDelegate <NSObject>
@required
- (void)dataFromController:(NSString *)data;
@end
@interface CViewController : UIViewController
@property (nonatomic, weak) id<SecondViewControllerDelegate> delegate;
@end
in CViewController.m
- (IBAction)btnBackAction:(id)sender {
if([_delegate respondsToSelector:@selector(dataFromController:)])
{
[_delegate dataFromController:@"Data Received"];
}
[self.navigationController popViewControllerAnimated:YES];
}
in A or BViewController (where you want to come back from C)
// not forget to import CViewController.h
@interface A OR BViewController : UIViewController<SecondViewControllerDelegate>
now in A or BViewController.m
// when you go to CViewController from A Oor B then you have to pass delegate like
CView.delegate = self;
- (void)dataFromController:(NSString *)data
{
// this method invokes when you come back from CViewController
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 250, 50)];
label.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleBottomMargin;
label.textAlignment = NSTextAlignmentCenter;
label.text = [NSString stringWithFormat:@"Your data: %@", data];
[self.view addSubview:label];
}