1

在我firstviewcontroller提出了一个modalviewcontroller,然后通过一个动作我调用了一个显示警报并关闭的方法modalview,但是当它消失时 viewWillAppear 不会被调用:

第一视图控制器

-(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没有被调用,我想念什么

4

2 回答 2

6

更改以下代码它将起作用:

 addViewController.modalPresentationStyle = UIModalPresentationFullScreen;

它会工作。

于 2017-01-05T06:43:12.360 回答
-2

问题是视图消失时不会调用 viewWillAppear 。您正在寻找的方法是 viewWillDisappear。

有关其他说明,请参见下文。

– viewWillAppear:在视图出现之前调用。

– viewDidAppear:当视图出现时调用(在屏幕上可见)。

– viewWillDisappear:在视图消失之前调用。

– viewDidDisappear:当视图消失时调用(在屏幕上不可见)。

还要确保您的代码正确编写,如下所示:

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

-(void)viewWillDisappear:(BOOL)animated {
    // work your magic here
}
于 2013-08-05T17:02:47.710 回答