0

i am new to iOS, so i am confronted with this problem: I wrote an UICollectionView in an UIViewController (parent) with an UICollectionResuableView as a header.

class ParentViewController: UIViewController, SideBarDelegate {

@IBOutlet weak var mPreviewsCollection: UICollectionView!

override func viewDidLoad() {
    ...
}
...
}

This UICollectionResuableView contain another UICollectionView (child) to provide dynamic customized tabs (maybe not the best idea, but it looks as was intended).

class ChildHeaderCollectionReusableView: UICollectionReusableView {

@IBOutlet var mTabHeader: UICollectionView!

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    ...
}
...

Now i want to to change the content of the parent UICollectionView (reloadData()) when selecting a cell in the child. How can i do that? How can i execute methods in the running instance of the parent from outside? e.g. var rootViewController = self.window!.rootViewController as KioskViewController returns another instance of my parent UIViewController with zero content

HappyCoder
  • 23
  • 6
  • Use the [delegate pattern](https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/DesignPatterns.html#//apple_ref/doc/uid/TP40011343-CH5-SW4). Here's a [tutorial in Obj-C](http://www.tutorialspoint.com/ios/ios_delegates.htm) but the same concepts apply in Swift. – Aaron Brager Mar 04 '15 at 14:02
  • I think i should have spent more time with that pattern. At first it didn´t work, but setting the delegate on the header worked out. Thank you very much – HappyCoder Mar 05 '15 at 09:23

0 Answers0