views:

32

answers:

1

I need to change the value of a variable of the previous view when the default back button is selected. How can I develop this using viewControllers in an iphone application?

I tried to do it by creating a custom back button and by set method. I call both these methods in viewWillDisappear method.

-(void)viewWillDisappear:(BOOL)animated{
    // Initialize next table view controller and set data to that view.
    FTTestSummaryTableViewController *testSummaryViewController  = 
        [[FTTestSummaryTableViewController alloc]
         initWithNibName:@"FTTestSummaryTableViewController" bundle:nil];
    [testSummaryViewController setCurrentIndex:self.currentIndex];
}

I couldn't pass the current Index value from existing view to previous view by using these methods. When I go to previous view it always displays its last currentIndex value other than the value which set using setCurrentIndex.

What is problem with my code, or is there any other way I can accomplish this.

A: 

Try having a reference to 'first' view on 'second' view.

FirstViewController.m

  SecondViewController *second = [SecondViewController alloc] init...];
  second.first = self;
  [self.navigationController pushViewController:second animated:YES];

SecondViewController.h

  FirstViewController *first;
  @property(nonatomic, retain) FirstViewController *first;

SecondViewController.m

- (void) viewWillDissappear
{ 
    self.first.some_property = @"something";
}
sujee