【问题标题】:monotouch UICollectionView is giving null reference errormonotouch UICollectionView 给出空引用错误
【发布时间】:2014-03-05 16:22:34
【问题描述】:

我是单点触控的新手。我有一个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); 处给出空引用异常

请告诉我我做错了什么

【问题讨论】:

    标签: c# ios xamarin.ios uicollectionview nib


    【解决方案1】:

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

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

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

    【讨论】:

    • 如果我将 RegisterNibForCell 移动到 ViewDidLoad 并放置一个断点,它永远不会到达 ViewDidLoad
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多