繁体   English   中英

添加子视图将释放父视图控制器的属性

[英]Adding a subview releases properties of parent view controller

我在主视图控制器(parentView)上添加了一个子视图(childView),用于从菜单中选择某些选项。 但是,当我从视图中删除它时,父视图的属性返回null。 任何人都可以解释这种行为。 我也在使用ARC。

这就是我添加子视图的方式:

resolutionPopUp=[ResolutionPopUp alloc];
resolutionPopUp.resPopStr = combinedUrl;
[self.view addSubview:resolutionPopUp.view];

当我使用以下方式删除子视图时:

[self.view removeFromSuperview];

现有视图控制器的所有属性均返回null。

[self.view removeFromSuperview]删除从其父父视图(这将是一个UIWindow ),并在结果self.view被garbaged收集。 删除子视图resolutionPopUp.view的正确方法是:

[resolutionPopUp.view removeFromSuperview];

这将从self.view删除resolutionPopUp.view

self.view是您的parentViewController。您将其删除,因此这是获得null值的主要原因。 而不是那个,用户

     resolutionPopUp=[ResolutionPopUp alloc];
      resolutionPopUp.resPopStr = combinedUrl;
       [self.view addSubview:resolutionPopUp.view];
      [resolutionPopUp.view removeFromSuperView];

这是正确的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM