Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Trigger events when switching views
  2. secondView *secondViewController;
  3. secondViewController = [[SecondView alloc]
  4.                       initWithNibName:@"SecondView" bundle:nil];
  5. [self.view addSubview:SecondViewController.view];
  6.        
  7. [self.view removeFromSuperView];
  8.        
  9. [self.navigationController pushViewController:secondViewController animated:YES];
  10.        
  11. - (void) backButtonClicked:(id)sender {
  12.     [self.view removeFromSuperView];
  13.     [[NSNotificationCenter defaultCenter] postNotificationName:@"back"
  14.                                                         object:self.view];
  15. }
  16.        
  17. - (void) pushSecondViewController {
  18.     [[NSNotificationCenter defaultCenter] addObserver:self
  19.                                              selector:@selector(secondViewDidGoBack:)
  20.                                                  name:@"back"
  21.                                                object:secondViewController.view];
  22.  
  23.     SecondView *secondViewController = [[SecondView alloc] initWithNibName:@"SecondView"
  24.                                                                     bundle:nil];
  25.     [self.view addSubview:secondViewController.view];
  26. }
  27.  
  28. - (void) secondViewDidGoBack:(NSNotification *)notification {
  29.     [[NSNotificationCenter defaultCenter] removeObserver:self];
  30.  
  31.     NSLog(@"My Second View Did Go back !");
  32. }