views:

23

answers:

2

is there something that can call a -(void) every time a view shows. I am rotating between two views, so when i go to the second view and then return to the first view I want a void to be called automatically from the first view I've try to do this with -(void)viewWillAppear:(BOOL)animated and - (void)viewDidLoad by putting a NSLog in them but it doesn't print when i return to the first view. any suggestions?

A: 

If you are updating the first view with data from the second, use an observer on the model that is being updated. If the second view is being removed as a subview, you can observe the subviews. Alternatively, you can use a block callback closure.

In the interface:

IBAction(^doOnClose)(void);

and:

@property (nonatomic, copy) IBAction(^doOnClose)(void);

In the method that closes your second view:

if(doOnClose) doOnClose();

And finally to define it from your first view:

view2.doOnClose = ^{/*Do this when view 2 closes*/};
Peter DeWeese
I didn't really got what you are suggesting so please elaborate if you can. here is my code
Spire
A: 

I have two methods in the app delegate

-(void)goTo1{ 

 [self.window addSubview:[viewController view]]; 
 [settingsViewController.view removeFromSuperview];


 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:1.0];
  //removing the settingsViewController form the view and setting the animation
  [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:NO];

  [UIView commitAnimations];
  [settingsViewController release];
  settingsViewController = nil; }

and

-(void)goTo2{

 //calling the .xib file and the SettingsViewController
 SettingsViewController *aSettingsView = [[SettingsViewController alloc] initWithNibName:@"Settings" bundle:nil];
 [self setSettingsViewController:aSettingsView];
 [aSettingsView release];

 [self.window addSubview:[settingsViewController view]];
 //moving the view 30px down
 [[settingsViewController view] setFrame:CGRectMake(0, 20, 320, 460)];

 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:1.0];
 //setting the animation
 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];

 [UIView commitAnimations]; 
 [webskiAppBetaViewController release];
 webskiAppBetaViewController = nil;
}

and IBActions in the 2 view controllers first One

-(IBAction)goToView2{

 WebskiAppBetaAppDelegate *mainDelegate = (WebskiAppBetaAppDelegate *)[[UIApplication sharedApplication] delegate];
 [mainDelegate goTo2]; 
}

and second one

-(IBAction)goToView1{
 WebskiAppBetaAppDelegate *maniDelegate = (WebskiAppBetaAppDelegate *)[[UIApplication sharedApplication] delegate];
 [maniDelegate goTo1];
}

so now when i call goToVIew1 I also want to run a method that is in the view 1

something like this

-(IBAction)goToView1{

 WebskiAppBetaAppDelegate *maniDelegate = (WebskiAppBetaAppDelegate *)[[UIApplication sharedApplication] delegate];
 [maniDelegate goTo1];
[self methodInFirstVIew]; //this method is in the first view
}
Spire