代码之家  ›  专栏  ›  技术社区  ›  Spire

显示视图时调用void

  •  0
  • Spire  · 技术社区  · 15 年前

    是否有什么东西可以在每次视图显示时调用-(void)。 我在两个视图之间旋转,所以当我转到第二个视图,然后返回第一个视图时,我希望从第一个视图自动调用一个空。 我尝试使用-(void)viewwillappear:(bool)animated和-(void)viewdidload进行此操作。 把一个nslog放进去,但当我回到第一个视图时它就不打印了。 有什么建议吗?

    2 回复  |  直到 15 年前
        1
  •  0
  •   Peter DeWeese    15 年前

    如果要使用来自第二个视图的数据更新第一个视图,请在正在更新的模型上使用观察者。如果第二个视图作为子视图被删除,则可以观察子视图。或者,可以使用块回调闭包。

    在界面中:

    IBAction(^doOnClose)(void);
    

    还有:

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

    在关闭第二个视图的方法中:

    if(doOnClose) doOnClose();
    

    最后,从第一个视图定义它:

    view2.doOnClose = ^{/*Do this when view 2 closes*/};
    
        2
  •  0
  •   Spire    15 年前

    我在应用程序委托中有两种方法

    -(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; }
    

    -(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;
    }
    

    和2个视图控制器中的i操作 第一个

    -(IBAction)goToView2{
    
     WebskiAppBetaAppDelegate *mainDelegate = (WebskiAppBetaAppDelegate *)[[UIApplication sharedApplication] delegate];
     [mainDelegate goTo2]; 
    }
    

    第二个

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

    所以现在,当我调用GoToview1时,我还想运行视图1中的方法

    像这样的东西

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