Search code examples
iphoneviewwillappear

ViewWillAppear query in iphone


I have set the following code in a viewWillAppear method.

- (void)viewWillAppear:(BOOL)animated 
 {  
     //some code of ausregion
     mapView.region = AusRegion;
     mapView.showsUserLocation = NO;
     addressField.text = [NSString stringWithFormat:@""];
     [super viewWillAppear:animated];
 }

It opens well when my application launch first screen. This is my map application and I have set code on button click event to perform some action. [eg. textfield get filled with current address and map get zoom in to current location with annotation]. Now when I jump on another list view controller and get back to my first screen the - (void)viewWillAppear:(BOOL)animated method again get called with blank textfield, no current location etc. I want to retain the screen with previous changes [eg. textfield filled with current address and map zoom in to current location with annotation]. after returning from listview controller to my first screen.

How should I achieve this?

Edited: I am calling list view controller on following action

     RootViewController *list =
[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    [self presentModalViewController:list animated:YES];

And after returning from RootViewController I want Map View with current annotation as I performed action before getting list view in RootViewController instead of just Australia continent.


Solution

  • Try using viewDidLoad instead of viewWillAppear. Then that code will only run when the view is loaded (from the nib), and not every time it will re-appear.