我是单点触控的新手。我有一个 UICollectionViewCell
.xib 文件,我在其中设置了图像和标签。在另一个类似
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] CollectionView
属性此时为 null
- 即在 TestViewController
类型的构造函数中.
稍后(例如,当 ViewDidAppear
被调用时)它可能会(由 iOS)设置为有效(非空)值。在这种情况下,您应该在稍后的执行过程中将调用移至 RegisterNibForCell
。
[1] 您可以使用调试器查看任何字段/属性的值。
关于c# - monotuch UICollectionView 给出空引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22203331/