【问题标题】:Presenting modalViewController is dealloc'ing the one calling it呈现 modalViewController 正在释放调用它的那个
【发布时间】:2012-07-14 00:32:28
【问题描述】:

我在集成 Greystripe 广告时遇到了一些问题(记录在 here 但并不重要)。如果像这样展示我的游戏视图,可以解决我的问题

iSlideAppDelegate *appDelegate = (iSlideAppDelegate *)[[UIApplication sharedApplication] delegate];
            UIStoryboard *storyboard = self.storyboard;
            Game3ViewController *gameView = (Game3ViewController *)[storyboard instantiateViewControllerWithIdentifier:@"mainGameController"];
            [appDelegate.window addSubview:gameView.view];

这基本上只是将我的游戏视图添加到当前视图控制器之上。

现在我想从这个视图中显示另一个像这样的模态视图

FullScreenSelfAdViewController *adView = [[FullScreenSelfAdViewController alloc] initWithNibName:@"FullScreenSelfAdViewController" bundle:nil];
        [adView setDismissDelegate:self];
        [self presentModalViewController:adView animated:YES];

问题是,当显示此视图时,我的 gameView 会释放。这意味着当我调用解除它的 AdView 时,它会释放但仍留在屏幕上,因为底层的 gameView 不再存在。

有没有更好的方法来调用这些视图? (我不能通过将它呈现为模态视图来调用我的游戏视图)。 或者有一种方法可以防止 gameView 被释放?

【问题讨论】:

    标签: ios xcode cocoa-touch uiviewcontroller modalviewcontroller


    【解决方案1】:

    如果我不得不猜测,你没有一个强变量来保留被释放的类。创建该类的人应该有一个强大的 ivar 这样做。当我尝试创建一个对象并在不保留它的情况下使用它时,我遇到了同样的问题。请注意,对于 UIAlerts,当您调用 [alert show] 时系统会保留它,导致您认为您可以使用其他视图控制器执行此操作(您不能!)

    祝你好运。

    【讨论】:

    • 谢谢。创建一个强变量有效。有趣的是,你忽略了大部分时间都在做的事情。
    • 哈,问我怎么知道答案的:-)
    • 我估计要花几个小时才能弄清楚为什么某些东西无法保留。大声笑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多