2011-10-24 20 views
0

我有兩個視圖與他們的控制器。 應用程序以FirstViewController開頭。 然後用一個按鈕打開SecondViewController識別我何時返回ViewController

使用其他按鈕,我忽略SecondViewController返回到FirstViewController

有沒有什麼辦法可以檢測到FirstViewController它已經恢復了焦點?

編輯:好吧,我看看答案,我用viewWillAppear但如果我使用UIModalPresentationFormSheet不工作。

-(IBAction)openSecondView{ 
    SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil]; 
    screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
    screen.modalPresentationStyle = UIModalPresentationFormSheet; 
    [self presentModalViewController:screen animated:YES]; 
    [screen release]; 
} 

然後用關閉按鈕關閉此視圖。

viewWillAppear從未叫過。

回答

1

添加一個委託(協議)方法viewWillAppear內UIViewController的viewWillAppear中方法

- (void) viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 

} 
2

實施的FirstViewController

- (void) viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 
    NSLog(@"view 1 focused"); 
} 
+0

我用它但沒有工作。 。 謝謝。 – JSanchez

0

。在關閉SecondViewController之前調用委託方法。

有關委託的詳細信息,請參閱delegate

0

實施viewWillAppear中的:回調將工作只有在使用導航控制器或tabbarcontroller顯示另一個控制器+這樣的方法,你將需要以某種方式檢查,如果這僅僅是該視圖的第一次出現,或者被任何其他原因調用;

使用代理,如上面Gomathi所述是一個更好的選擇!

0

取決於您如何設置第一個視圖控制器。將它封裝在UINavigationViewController中(如果你不需要導航欄,你可以隨時將其設置爲隱藏([self.navigationController.navigationBar setHidden:YES])。ViewWillAppear將工作。

相關問題