1
votes

Im presenting and dismissing a Modal View Controller. I use delegation so I dismiss the modalView at the Parent.

- (void)launchDrawingSection{

    drawingSectionViewController = [[DrawingSectionViewController alloc] init];
    drawingSectionViewController.modalTransitionStyle = UIViewAnimationTransitionFlipFromLeft;
    drawingSectionViewController.drawingModalDelegate = self;
    [self presentModalViewController:drawingSectionViewController animated:YES];
}


- (void)didDismissDrawingModalView{

    NSLog(@"didDismissDrawingModalView");
    [drawingSectionViewController release];
    [self dismissModalViewControllerAnimated:YES];
}

The app crashes after the dealloc method in the ModalView gets called.

Am I doing something wrong with the way I present and dismiss a Modal View Controller? Any idea?

2
If it is crashing in the modal view controller's dealloc, you must probably be over releasing one of its instance variables. Any crash logs?Deepak Danduprolu
when does didDismissDrawingModalView method gets called?user745098
It is called when I exit the ModalView. It is a Protocol method I use so the ParentView is the one that dismisses the modalview.Canelo
What do you mean by "exit" ModalView? The DrawingModalView was presented as a modal view controller. The only way it should exit is to "dismiss". As your function name "didDismissDrawingModalView" indicates that DrawingModalView already "did" dismiss, then why is it getting once again dismissed?user745098
It is just a bad function name. In the ModalView I have a function named DismissView, which tells the Delegate(ParentView) function didDismissDrawingModalView to dismiss the View. So it is dismissed just once.Canelo

2 Answers

0
votes

Don't release before dismiss.

- (void)launchDrawingSection{

        drawingSectionViewController = [[DrawingSectionViewController alloc] init];

        drawingSectionViewController.modalTransitionStyle =          UIViewAnimationTransitionFlipFromLeft;

        drawingSectionViewController.drawingModalDelegate = self;

        [self presentModalViewController:drawingSectionViewController animated:YES];

        [drawingSectionViewController release];    


}




- (void)didDismissDrawingModalView{
    NSLog(@"didDismissDrawingModalView");

    [self dismissModalViewControllerAnimated:YES];


}
0
votes

Your fundamentals of Modal View Controller is not clear. If you are using delegate protocols only to inform the drawing sections's parent control to dismiss the drawing section controller, then this is something useless. Because, the following thing does your job without use of delegates.

// Present drawing section.
- (void)launchDrawingSection{

    drawingSectionViewController = [[DrawingSectionViewController alloc] init];
    drawingSectionViewController.modalTransitionStyle = UIViewAnimationTransitionFlipFromLeft;
    drawingSectionViewController.drawingModalDelegate = self;
    [self presentModalViewController:drawingSectionViewController animated:YES];
    [drawingSectionViewController release];
}

// (Put this in Drawing Section View Controller). This function dismisses drawing section.
- (void)dismissActionEvent{
    // Drawing section view controller is asking its parent to dismiss it.
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

To understand clearly how presenting and dismissing modal view controller's work, refer to my answer here