Iphone 拆卸ABBARC控制器

Iphone 拆卸ABBARC控制器,iphone,uitabbarcontroller,Iphone,Uitabbarcontroller,有人发布了一个类似的问题,没有解决方案,但也没有示例代码。所以,我想我会在这里详细地发布我的问题 我有一个游戏有几种游戏模式,每种模式都有几种选择。在玩过各种各样的设计之后,把它们放进一个带有三个标签的UtiAbbarController中似乎是最干净的,每类游戏一个标签。我创建了一个新的UIVIewController,它从主菜单屏幕(替换主屏幕)加载,并按如下方式初始化UIDABBARCONTROLLER: barController = [[UITabBarController alloc

有人发布了一个类似的问题,没有解决方案,但也没有示例代码。所以,我想我会在这里详细地发布我的问题

我有一个游戏有几种游戏模式,每种模式都有几种选择。在玩过各种各样的设计之后,把它们放进一个带有三个标签的UtiAbbarController中似乎是最干净的,每类游戏一个标签。我创建了一个新的UIVIewController,它从主菜单屏幕(替换主屏幕)加载,并按如下方式初始化UIDABBARCONTROLLER:

barController = [[UITabBarController alloc] init];

Games1 *vc1 = [[[Games1 alloc] initWithNibName:@"Games1" bundle:nil] autorelease];
Games2 *vc2 = [[[Games2 alloc] initWithNibName:@"Games2" bundle:nil] autorelease];
Games3 *vc3 = [[[Games3 alloc] initWithNibName:@"Games3" bundle:nil] autorelease];

NSArray* controllers = [NSArray arrayWithObjects:vc3, vc1, vc2, nil];
barController.viewControllers = controllers;
[self.view addSubview:barController.view];
- (void)dealloc {
    printf("Games released: barController: %d\n", [barController retainCount]);
    [barController.view removeFromSuperview];
    barController.viewControllers = 0;
    [barController release];
    barController = 0;
    [super dealloc];
}
当用户选择游戏时,我将UIViewController从窗口中移除,并按如下方式解除分配:

barController = [[UITabBarController alloc] init];

Games1 *vc1 = [[[Games1 alloc] initWithNibName:@"Games1" bundle:nil] autorelease];
Games2 *vc2 = [[[Games2 alloc] initWithNibName:@"Games2" bundle:nil] autorelease];
Games3 *vc3 = [[[Games3 alloc] initWithNibName:@"Games3" bundle:nil] autorelease];

NSArray* controllers = [NSArray arrayWithObjects:vc3, vc1, vc2, nil];
barController.viewControllers = controllers;
[self.view addSubview:barController.view];
- (void)dealloc {
    printf("Games released: barController: %d\n", [barController retainCount]);
    [barController.view removeFromSuperview];
    barController.viewControllers = 0;
    [barController release];
    barController = 0;
    [super dealloc];
}
我遇到的问题是,当我旋转设备时,会发生碰撞。如果我直接从主屏幕启动游戏模式并旋转,则不会发生崩溃。我已经确认所有东西都被释放了,我在酒吧控制器上的保留计数是1。关于如何消除这次事故有什么建议吗?谢谢

[编辑]更多信息:

barController的定义如下:

IBOutlet UITabBarController *barController;
与:

不要这样做:

barController.viewControllers = 0;

在-dealloc中,您应该只从超级视图中删除UITabBarController的视图并将其释放。

结果是问题仅与UITabBarController外围相关。我直接在我的应用程序窗口中添加和删除UIViewControllers,这在其他地方造成了问题。添加主UIViewController/UIView并仅从中添加和删除可以修复所有问题,尽管自动释放而不是发布也可能起作用。请参见此处的讨论:


UITabBarController只是让问题发生得更快更明显。

谢谢您的建议。我把那条线插进去是为了解决问题;移除它并没有什么区别。