OGeek|极客世界-中国程序员成长平台

标题: c# - monotouch UICollectionView 给出空引用错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 19:52
标题: c# - monotouch UICollectionView 给出空引用错误

我是单触的新手。我有一个 UICollectionViewCell .xib 文件,其中设置了图像和标签。在另一个类似于

的 View Controller 中
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); 处给出空引用异常;

请告诉我我做错了什么



Best Answer-推荐答案


看起来 [1] CollectionView 属性此时为 null - 即在您的 TestViewController 类型的构造函数中.

稍后(例如,当调用 ViewDidAppear 时)可能会(由 iOS)将其设置为有效(非空)值。在这种情况下,您应该在稍后执行时将调用移至 RegisterNibForCell

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

关于c# - monotouch UICollectionView 给出空引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22203331/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4