Wednesday, 22 April 2015

Pass value to parent controller when popview(or)dismiss the controller

Put this code in your parent controller

- (void)viewDidLoad {
    [super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(BackButtonNotification:)
                                      name:@"POPVIEW" object:nil];

(OR)

[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(BackButtonNotification:)
                                      name:@"DISMISS" object:nil];
 }


-(void)BackButtonNotification:(NSNotification *)notice{
    NSString *value = [notice object];
    NSLog(@"value: %@",value);
}

Put this code in your child controller back button action place

-(void)navigationShouldPopOnBackButton{

   [self.navigationController popViewControllerAnimated:YES];

    [[NSNotificationCenter defaultCenter]
          postNotificationName:@"POPVIEW"
                        object:@"You pass value to parent class"];
}

                    (OR)
                 
-(void)dissmissModelView{

    [self dismissModalViewControllerAnimated:YES];

 [[NSNotificationCenter defaultCenter]
          postNotificationName:@"DISMISS"
                        object:@"You pass value to parent class"];
}

No comments:

Post a Comment