2010-09-22 50 views
0

有沒有什麼東西可以在每次顯示視圖時調用 - (void)。 我在兩個視圖之間旋轉,所以當我轉到第二個視圖,然後返回到第一個視圖時,我想從第一個視圖自動調用一個void 我試着用 - (void)viewWillAppear來做到這一點: (布爾)動畫和 - (void)viewDidLoad 通過放入NSLog中,但它不會打印時,我回到第一個視圖。 有什麼建議嗎?在顯示視圖時調用void 0

回答

0

如果使用第二個數據更新第一個視圖,請在正在更新的模型上使用觀察者。如果第二個視圖作爲子視圖被刪除,您可以觀察子視圖。或者,您可以使用塊回調關閉。

在接口:

IBAction(^doOnClose)(void); 

和:

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

在封閉你的第二個觀點的方法:

if(doOnClose) doOnClose(); 

最後從你的第一個視圖定義它:

view2.doOnClose = ^{/*Do this when view 2 closes*/}; 
+0

我並沒有真正得到你的建議是什麼,請詳細說明,如果你的方法能夠。這是我的代碼 – Spire 2010-09-22 13:23:17

0

我在應用程序委託兩種方法

-(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個視圖控制器 第壹

-(IBAction)goToView2{ 

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

和第二

和IBActions一個

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