2013-08-05 37 views
0

在我firstviewcontroller我提出一個modalviewcontroller,然後通過一個動作我打電話,顯示警報的方法和罷免modalview,但是當它消失viewWillAppear中不叫:viewWillAppear中不叫modalviewwontroller

firstviewcontroller

-(IBAction)AddActivity:(id)sender{ 


    CreateActivity *addViewController = [[CreateActivity alloc] initWithNibName:@"CreateActivity" bundle:nil]; 

    addViewController.delegate = self; 
    addViewController.modalPresentationStyle = UIModalPresentationFormSheet; 

    addViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 

    [self presentModalViewController:addViewController animated:YES]; 


    addViewController.view.superview.frame = CGRectMake(50, 260, 680, 624); 

} 
//in secondviewcontroller I use an alert view that call this method in order to dismiss modalview 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if (buttonIndex == 0){ 


     if ([self respondsToSelector:@selector(presentingViewController)]){ 
      [self.presentingViewController dismissModalViewControllerAnimated:YES]; 
     } 
     else { 
      [self.parentViewController dismissModalViewControllerAnimated:YES]; 
     } 
    } 
} 

,當它消失,viewWillAppear不叫,我所缺少的,請

回答

0

問題是viewWillAppear在視圖消失時未被調用。您正在查找的方法是viewWillDisappear。

請參閱下面的其他說明。

- viewWillAppear: 在視圖出現之前調用。

- viewDidAppear: 當視圖出現時調用(在屏幕上可見)。

- viewWillDisappear: 在視圖消失之前調用。

- viewDidDisappear: 視圖消失時調用(屏幕上不可見)。

另外,還要確保你的代碼編寫正確,像這樣:

- void)viewWillAppear:(BOOL)animated { 
    // work your magic here 
} 

-(void)viewWillDisappear:(BOOL)animated { 
    // work your magic here 
} 
+0

感謝您的回覆,即使我添加viewwilldisappear時,它也無法訪問我的第一個視圖控制器的視圖 –

+0

您是否正在使用導航控制器?你也可以發佈你的viewWillAppear代碼嗎? – dana0550

+0

不,我只是目前modaly我的viewcontroller,並想解僱它,然後調用viewwillappear來做一些操作 –

2

更改下面的代碼將工作:

addViewController.modalPresentationStyle = UIModalPresentationFullScreen; 

它會奏效。

+0

這不是一個解決方案。 1)如果我需要另一種演示風格,該怎麼辦? 2)當呈現視圖控制器出現時,背景視圖變成黑色並且不好 –

相關問題