0

我的应用程序中有这段代码可以为视图控制器进行转换

SecondViewController *second = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
    [self.view addSubview:second.view];
    [second.view setFrame:CGRectMake(320, 0, 320, 480)];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.40]; //the double represents seconds
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [second.view setFrame:CGRectMake(0, 0, 320, 480)];
    [UIView commitAnimations];

它工作正常;但在第二个视图控制器中,我有这段代码可以让这个视图控制器消失

[UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.40]; //the double represents seconds
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [self.view setFrame:CGRectMake(320, 0, 320, 480)];
    [UIView commitAnimations];

它工作正常,但是释放它的方法是什么,我在哪里可以释放我调用它时分配的这一秒?如果我写 [self.view removeFromSuperView]?? 发布了吗??

4

1 回答 1

0

您需要将其从 superView 中删除,然后释放您在代码中分配的 SecondViewController。

SecondViewController *second = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];

所以既然你拥有这个对象,你需要释放它。因此,在隐藏第二个视图并将其从 superView 中删除后,您需要释放它...

[second release];
于 2012-05-09T00:05:36.233 回答