Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIView:添加UIViewController';s视图作为子视图及其删除_Uiview_Uiviewcontroller_Release_Addsubview - Fatal编程技术网

UIView:添加UIViewController';s视图作为子视图及其删除

UIView:添加UIViewController';s视图作为子视图及其删除,uiview,uiviewcontroller,release,addsubview,Uiview,Uiviewcontroller,Release,Addsubview,我想问一下,作为子视图添加和删除UIViewController视图的正确方法是什么。 因此,初始化UIViewController后,我可以将其视图添加到视图层次结构中,如下所示: UIViewController *myViewControler = [[UIViewController alloc] init]; [someAnotherView addSubview:myViewController.view]; 问题1:我应该在addSubview:call之后释放myViewCon

我想问一下,作为子视图添加和删除UIViewController视图的正确方法是什么。 因此,初始化UIViewController后,我可以将其视图添加到视图层次结构中,如下所示:

UIViewController *myViewControler = [[UIViewController alloc] init];
[someAnotherView addSubview:myViewController.view];
问题1:我应该在
addSubview:
call之后释放myViewController.view吗

如果我想从视图层次结构中删除myViewController的视图,我调用
[myViewController.view removeFromSuperview]

问题2:在这种情况下,当myViewController实例的视图从SuperView中移除后,我应该如何释放它

  • 您不需要释放视图,拥有视图的控制器将为您执行此操作

  • 我通常将myViewController的声明放在标题中,然后在处理完它后将其释放并置零(在正常流中的某个地方或包含该视图控制器的dealoc中)


  • 关于2:如果我只是释放myViewController,它的视图将不会被删除,如果我有正确的理解。。。因此,在这种情况下,[myViewController.view removeFromSuperview]是否正确;然后[myViewController release]?这是正确的,移除视图并在不再需要它们的位置释放控制器。