monotouch UICollectionView给出null引用错误

时间:2014-03-05 16:22:35

标签: c# ios xamarin.ios uicollectionview nib

我是monotouch的新手。我有一个UICollectionViewCell .xib文件,我有图像和标签集。在另一个像

的viewcontroller中
public partial class TestViewController : UICollectionViewController {

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

它在CollectionView.RegisterNibForCell (UINib.FromName ("imagesCollectionViewCell", NSBundle.MainBundle), imageCellId);

处提供空引用异常

请让我知道我做错了什么

1 个答案:

答案 0 :(得分:1)

此时CollectionView属性null看起来像[1],即在TestViewController类型的构造函数内部时。

稍后可能将(通过iOS)设置为有效(非空)值(例如,当调用ViewDidAppear时)。在这种情况下,您应该在执行后期将您的呼叫转移到RegisterNibForCell

[1]您可以使用调试器查看任何字段/属性的值。

相关问题