I choosed this solution:
1) Keep a reference to the view controllers whose views you wish to display in the cells of the collection view.
The following code is a simple view controller that demonstrates this, using your ChartTest view controller. Notice for simplicity that it subclasses UICollectionViewController and that the sizing parameters etc have been set up in a storyboard:
public class ViewController : UICollectionViewController {
let cellVCs = [ChartTest(), ChartTest(), ChartTest()]
public override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
public override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
public override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as UICollectionViewCell
cell.layer.borderWidth = 2;
cell.layer.borderColor = UIColor.blackColor().CGColor;
cell.addSubview(cellVCs[indexPath.item].view);
return cell
}
}
Note that the view controllers are retained in the cellVCs
array property.