在解雇modalviewwontroller后没有调用Viewwillappear

时间:2013-08-05 16:58:06

标签: ios objective-c uiviewcontroller

在我的firstviewcontroller我提交了一个modalviewcontroller,然后通过一个动作我调用了一个显示警告的方法并解除了modalview,但是当它消失时,viewWillAppear没有被调用:< / p>

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没有被调用,我缺少的是

2 个答案:

答案 0 :(得分:5)

更改以下代码:

 addViewController.modalPresentationStyle = UIModalPresentationFullScreen;

它会起作用。

答案 1 :(得分:0)

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

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

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

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

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

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

还要确保您的代码正确写入:

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

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