Xamarin.ios 无法将自定义XIB插座与UICollectionViewCell一起使用

Xamarin.ios 无法将自定义XIB插座与UICollectionViewCell一起使用,xamarin.ios,custom-controls,xib,uicollectionviewcell,Xamarin.ios,Custom Controls,Xib,Uicollectionviewcell,从my CustomClass:UICollectionViewCell访问插座时,插座显示为未初始化,无法设置正确的值 我看到的每个示例都使用普通类(无XIB)来设置UI [Register("CustomCommentCell")] public partial class CustomCommentCell : UICollectionViewCell { public static readonly NSString Identifier = new NSString("Cust

从my CustomClass:UICollectionViewCell访问插座时,插座显示为未初始化,无法设置正确的值

我看到的每个示例都使用普通类(无XIB)来设置UI

[Register("CustomCommentCell")]
public partial class CustomCommentCell : UICollectionViewCell
{
    public static readonly NSString Identifier = new NSString("CustomCommentCell");

    public CustomCommentCell () : base()
    {
    }

    public CustomCommentCell (IntPtr handle) : base (handle)
    {
    }

    public void updateData()
    {
        this.lblComment.Text = "Test";
    }
}
另一方面,我已经注册了班级: this.tableComments.RegisterClassForCell(typeof(CustomCommentCell),commentCellId)

并正确设置GetCell。 但是,当尝试将出口设置为特定值时,它表示该值为空。(this.lblcomment=null),而它本应是初始化的UILabel


有什么线索吗?

我不能完全理解你看到的问题。什么是“定制XIB插座”?为什么这个问题被标记为“自定义控件”?是否有一些示例代码或图片可以帮助您解释问题


我用于UICollectionViewCell的方法与用于UITableViewCell的方法相同-请参阅教程-



更新:根据您作为注释发布的代码(不确定是否完整),我认为您可以按照该教程进行操作。有几个步骤需要完成,包括注册自定义类名和使用
RegisternbforcellReuse
——其中一个步骤可能会为您解决这个问题。

使用XIB创建自定义CollectionViewCell。执行以下操作

1) 创建从UIcollectionViewCell继承的C#类

[Register("MyCustomCell")]
public class MyCustomCell : UICollectionViewCell
{

    public static readonly NSString Key = new NSString ("MyCustomCell");

    [Export ("initWithFrame:")]
    public MyCustomCell(CoreGraphics.CGRect frame) : base (frame)
    {



    }

    public override UIView ContentView {
        get {
            var arr=    NSBundle.MainBundle.LoadNib ("MyCustomCell", this, null);
            UIView view =arr.GetItem<UIView> (0);
            view.Frame = base.ContentView.Frame;
            base.ContentView.AddSubview (view);
            return base.ContentView;
        }
    }

} 
[注册(“MyCustomCell”)]
公共类MyCustomCell:UICollectionViewCell
{
公共静态只读NSString键=新NSString(“MyCustomCell”);
[导出(“initWithFrame:”)]
公共MyCustomCell(CoreGraphics.CGRect框架):基础(框架)
{
}
公共覆盖UIView内容视图{
得到{
var arr=NSBundle.MainBundle.LoadNib(“MyCustomCell”,this,null);
UIView=arr.GetItem(0);
view.Frame=base.ContentView.Frame;
base.ContentView.AddSubview(视图);
返回base.ContentView;
}
}
} 
2) 添加与步骤1中创建的类同名的IphoneView XIB文件

3) 在XCODE中打开XIB并执行以下更改

3.1)选择文件所有者并设置与步骤1相同的类名 3.2)选择视图设置类名UIView


4) 相应地设计您的XIB

编辑您的问题并将完整代码粘贴到其中-我在评论中看不到这一点。我添加了this.tableComments.RegisterClassForCell。this.tableComments.RegisterClassForCell(typeof(CustomCommentCell),commentCellId);如果我删除它,我会在GetCell方法中得到一个错误。一切似乎都正常,intellisense中出现了插座,但只是没有初始化。请尝试示例教程或发布更多代码。我无法在这样的评论中调试您的问题。我可以告诉你,这个流程是有效的,我对收集单元格和表单元格都使用相同的流程。为了更好地描述,我遇到了同样的问题: