gpt4 book ai didi

iphone - UIView在removeFromSuperview后继续存在

转载 作者:行者123 更新时间:2023-12-03 19:47:45 25 4
gpt4 key购买 nike

我在 AppDelegate 中添加一个firstView:

#import "TestViewAppDelegate.h"
#import "MainViewController.h"
@implementation TestViewAppDelegate

@synthesize window;
@synthesize mainViewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
self.mainViewController = aController;
[aController release];

self.mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window makeKeyAndVisible];
[window addSubview:mainViewController.view];
}

- (void)dealloc {
[mainViewController release];
[window release];
[super dealloc];
}

然后我想切换到第二个View:

#import "MainViewController.h"
#import "SecondViewController.h"

@implementation MainViewController

@synthesize mainViewController, secondViewController;

- (IBAction)viewSwitch
{
SecondViewController *second = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
self.secondViewController = second;
[second release];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

[mainViewController.view removeFromSuperview];
[self.view addSubview:secondViewController.view];

[UIView commitAnimations];
}

- (void)dealloc {
[mainViewController release];
[secondViewController release];
[super dealloc];
}

@end

然后从第二个 View 切换到第一个 View 也是同样的事情......

问题是当我切换 View 时我认为要释放的 View 始终可见并且不会消失。

Download the full code

最佳答案

[mainViewController.view removeFromSuperview];
[self.view addSubview:secondViewController.view];

这里的“ self ”是什么?为什么 MainViewController 类有一个名为 mainViewController 的属性?探索这些问题可能会让您在这里找到答案。

关于iphone - UIView在removeFromSuperview后继续存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1514205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com