解雇模态视图控制器后崩溃

时间:2011-07-04 16:45:06

标签: iphone objective-c ios4

我提出并解雇模态视图控制器。我使用委托,所以我解除了父母的modalView。

- (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];
}

在调用ModalView中的dealloc方法后,应用程序崩溃。

我在呈现和解雇模态视图控制器时出错了吗?有什么想法吗?

2 个答案:

答案 0 :(得分:0)

请勿在解雇前释放。

- (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];


}

答案 1 :(得分:0)

您对模态视图控制器的基本原理尚不清楚。 如果您仅使用委托协议通知绘图部分的父控件解除绘图部分控制器,那么这是无用的。因为,以下事情可以在不使用代表的情况下完成工作。

// 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];
}

要清楚地了解如何呈现和解除模态视图控制器的工作,请参阅我的回答here