Question

I am new to monotouch. I have a UICollectionViewCell .xib file where I have image and label set. In another viewcontroller which is like

public partial class TestViewController : UICollectionViewController {

    public TestViewController (UICollectionViewLayout layout) : 
        base ("TestViewController", null)
    {
        CollectionView.RegisterNibForCell (UINib.FromName (
            "imagesCollectionViewCell", NSBundle.MainBundle), imageCellId);
    }
}

it gives null reference exception at CollectionView.RegisterNibForCell (UINib.FromName ("imagesCollectionViewCell", NSBundle.MainBundle), imageCellId);

Please let me know what I am doing wrong

No correct solution

OTHER TIPS

It looks like [1] the CollectionView property is null at this point of time - i.e. when inside the constructor of your TestViewController type.

It is likely set (by iOS) to a valid (non-null) value later (e.g. when ViewDidAppear is called). In that case you should move your call to RegisterNibForCell later in the execution.

[1] you can use the debugger to see the values of any fields/properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top