简体   繁体   English

uiview的子视图未清除

[英]subview of uiview not being purged

So i am using a Navigation controller to handle two view controllers. 所以我正在使用导航控制器来处理两个视图控制器。 One is ItemsViewController that is the root view controller of the NavController. 其中之一是ItemsViewController,它是NavController的根视图控制器。

The second controller named DetailViewController is pushed on top of ItemsViewController. 第二个名为DetailViewController的控制器被推到ItemsViewController的顶部。 This way i've made a drill-down UI using these 2 controllers. 这样,我就使用这2个控制器进行了下钻的UI。 Now inside DetailViewController i've added a couple of subviews like buttons, textfields, labels and an imageView . 现在在DetailViewController内,我添加了几个子视图,例如按钮,文本字段,标签和imageView

The imageView pointer that is declared inside of DetailViewController is of type 'weak', so whenever the view controller's main view is cleared off, the old imageView object doesn't hang around. 在DetailViewController内部声明的imageView指针的类型为“弱”,因此,每当清除视图控制器的主视图时,旧的imageView对象就不会徘徊。 But in reality i'm observing this behaviour. 但实际上,我正在观察这种行为。

What happens is, when i go back from DetailViewController's view to ItemsViewController's table view, the former is loaded off the parent-child controller stack so that when i re-enter the DetailViewController's view (same one as before),it is reloaded and thus recreating a UIView all over again. 发生的是,当我从DetailViewController的视图返回到ItemsViewController的表视图时,前者是从父子控制器堆栈中加载的,因此当我重新进入DetailViewController的视图(与以前相同)时,它会重新加载并因此重新创建UIView再次重新出现。

Thus the new UIView has got all the new subview objects created. 因此,新的UIView已创建了所有新的子视图对象。 But (and this is the problem), the old image object in the new imageView object is still there. 但是(这是问题所在), new imageView对象中的旧图像对象仍然存在。 This is confusing me. 这让我感到困惑。 Could someone clear this up? 有人可以解决这个问题吗?

ViewWillDisappear设置UIImageView如下所示,可以解决您的问题

imageView.image = nil 

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

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