当前位置: 代码迷 >> Iphone >> 如何release子视图
  详细解决方案

如何release子视图

热度:371   发布时间:2016-04-25 06:54:10.0
怎么release子视图?
[size=12px][/size]我在view中创建了一个新的view1,然后addsubview之后怎么处理view1才好?
   
  CustomViewController *customViewController = [[CustomViewController alloc] initWithNibName:@"CustomViewController "];
  [self.view addsubview:customViewController.view];
  [customViewController release];

  如上:如果我release customViewController self.view 上面显示的会只有一个customViewController.view的一个最上面的toolbar跳显示。可是如果我不release的话,会出现内存泄露吧。这个要怎么处理好。
  我有用 [[[CustomViewController alloc] initWithNibName] autorelease] 效果与后面release是一样的。
  求高手指点好的解决方案,最好讲解一下具体的原因,不胜感激。

------解决方案--------------------
用removeFromSuperview
------解决方案--------------------
3楼正解。

不过你的【customViewController 】是局部的,需要在创建的时候要么创建成类变量,要么在创建的时候保存下来,留着【removeFromSuperview】的时候用。
------解决方案--------------------
我们对由 UIViewController 持有的 View 都不会去处理的。
------解决方案--------------------
customViewController 直到不用的时候才release,不然你就不能control你的view。
  相关解决方案