In my view i added 4 UIButtons at bottom (something like tab bar application) and when I click on any button I added their respective subviews through add subview method , and when user click on another button a new subview is added on that view and so on. I am sure this is not a right way to do this task. so kindly suggest the way i could handle this situation while taking memory management into consideration.
在我的视图中,我在底部添加了4个uibutton(类似于tab bar应用程序),当我点击任何按钮时,我通过add subview方法添加了它们各自的子视图,当用户点击另一个按钮时,一个新的子视图就会添加到这个视图中,以此类推。我肯定这不是做这项工作的正确方法。因此,在考虑到内存管理的同时,请建议我如何处理这种情况。
2 个解决方案
#1
1
This can be done in two ways :
这可以通过两种方式实现:
- Add subview and then remove old subview when click on other button
- 添加子视图,然后在单击其他按钮时删除旧的子视图
- Add all subview first time and then show and hide them.
- 第一次添加所有子视图,然后显示和隐藏它们。
This is the proper way for memory management.
这是内存管理的适当方式。
#2
1
You can use UIViewController Containment
, The best thing I have found so far is the WWDC 2011 Session Video Session 102 - Implementing UIViewController Containment.
您可以使用UIViewController容器,我目前发现的最好的东西是WWDC 2011会话视频会话102 -实现UIViewController容器。
Container View Controller Examples
容器视图控制器的例子
#1
1
This can be done in two ways :
这可以通过两种方式实现:
- Add subview and then remove old subview when click on other button
- 添加子视图,然后在单击其他按钮时删除旧的子视图
- Add all subview first time and then show and hide them.
- 第一次添加所有子视图,然后显示和隐藏它们。
This is the proper way for memory management.
这是内存管理的适当方式。
#2
1
You can use UIViewController Containment
, The best thing I have found so far is the WWDC 2011 Session Video Session 102 - Implementing UIViewController Containment.
您可以使用UIViewController容器,我目前发现的最好的东西是WWDC 2011会话视频会话102 -实现UIViewController容器。
Container View Controller Examples
容器视图控制器的例子