iOS - 具有“强”参考父视图控制器的子视图控制器

时间:2015-12-26 01:48:10

标签: ios memory-leaks uiviewcontroller

我已经阅读了很多关于保留周期的内容。必要时,父级UIViewController应始终对其子级strong具有UIViewController引用,而子级则应对其父级weak提及UIViewController

仅当他们互相引用时才这样吗?例如,如果父级strong没有任何对其子级的引用,那么该子级是否可以对其父级UIViewController进行Task.cs引用?我能否解决这个问题,或者从长远的内存问题来看这是不好的做法?

1 个答案:

答案 0 :(得分:3)

来自function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i <ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length,c.length); } } return ""; }

UIViewController.h

/*
  If this view controller is a child of a containing view controller (e.g. a navigation controller or tab bar
  controller,) this is the containing view controller.  Note that as of 5.0 this no longer will return the
  presenting view controller.
*/
weak public var parentViewController: UIViewController? { get }

您可以在此处看到,父母与子// An array of children view controllers. This array does not include any presented view controllers. @available(iOS 5.0, *) public var childViewControllers: [UIViewController] { get } 之间已经已经 strongweak引用。您不应在从子级到父级的方向上添加任何新的ViewControllers引用,因为它可能导致内存泄漏。