UICollectionViewController没有获取父属性

时间:2019-01-24 09:32:10

标签: swift

我在从子$ dpkg -l | grep linux-headers- ii linux-headers-4.15.0-23 ii linux-headers-4.15.0-43 ii linux-headers-4.15.0-43-generic ii linux-headers-generic 属性访问父属性时遇到问题。

父级是模态的UICollectionViewController,添加了ChildViewController的代码看起来像

UICollectionViewController

let assetPickerController = AssetGridViewController(collectionViewLayout: GridFlowLayout()) addChildViewController(assetPickerController) let childView = assetPickerController.view! assetPickerController.par = self assetPickerController.nav = self.navigationController assetPickerController.didMove(toParentViewController: self) 具有以下代码,显示为nil

AssetGridViewController

但是它可以获取let svc = self as! UIViewController let parentSize = svc.parent!.view.frame.size print(parentSize) 属性(我自己创建)。我不太确定为什么会这样,这是一个par问题,还是因为它是模态下的子代而发生了?

1 个答案:

答案 0 :(得分:0)

将父级大小作为类的属性传递。

添加属性

var parentSize

放入assetPickerController,这样您就可以

assetPickerController.parentSize = self.view.frame.size //Before didMove
assetPickerController.didMove(toParentViewController: self)