【发布时间】:2012-01-06 18:35:06
【问题描述】:
我很难理解为什么下面的第一种方法可以隐藏和删除视图的子视图。在第一种方法中,我通过引用传递指针。在不太通用的第二种方法中,我有一个用于删除特定视图的委托方法。我想使用第一种方法,因为我有几个视图也想应用它。我应该提到,只要在实现类中调用第一种方法,它就不会失败。当我从我希望关闭的视图控制器调用它时,它失败了。当第一种方法失败时,我在 removeFromSuperview 行上得到一个 EXC_BAD_ACCESS。
-(void)closeView:(UIViewController **)viewController
{
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationOptionCurveLinear
animations:^
{
[[*viewController view] setAlpha:0.0];
}
completion:^(BOOL finished)
{
[[*viewController view] removeFromSuperview];
[*viewController release], *viewController = nil;
}];
}
-(void)closeButtonClicked
{
[delegate closeView:&self];
}
//
// This method works without fail:
//
-(void)closeView
{
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationOptionCurveLinear
animations:^
{
// In this context viewController is defined in the class interface
[[viewController view] setAlpha:0.0];
}
completion:^(BOOL finished)
{
[[viewController view] removeFromSuperview];
[viewController release], viewController = nil;
}];
}
-(void)closeButtonClicked
{
[delegate closeView];
}
【问题讨论】:
标签: ios animation delegates viewcontroller