jeudi 26 mars 2015

Xamarin iOS: How to connect a view from a storyboard to a controller?

I have an storyboard with a ViewController and inside the ViewController I have a UICollectionView with a prototype cell.


I already have an "MyCollectionViewController" (because I try to wrap my CollectionViewController in a ViewController). Now I want to reuse that controller but I can't figure out how to connect the CollectionView from the storyboard with a new CollectionViewController. Assigning the CollectionView from the CollectionViewController to the Outlet in the ViewController doesn't seem to work.


I know I could make the cell prototype a .xib file and create the CollectionView in code. But my employer prefers having everything in the storyboard for easier maintenance.


EDIT: The answer from chkn works great. To connect the parent view controller to the container you can override the PrepareSegue method like this.



public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
base.PrepareForSegue (segue, sender);
if (segue.SourceViewController == this) {
if (segue.DestinationViewController.GetType () == typeof(MyChildViewController)) {
MyChildViewController childViewController = segue.DestinationViewController as MyChildViewController;
}
}
}



Aucun commentaire:

Enregistrer un commentaire