2013-03-03 54 views
1

从我的CustomClass:UICollectionViewCell访问插座时,它们显示为未初始化并且无法设置适当的值。无法使用带有UICollectionViewCell的自定义XIB插座

我见过的每个例子都使用普通的类(无​​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初始化的。

任何线索?

回答

0

我无法遵循你所看到的很多问题。什么是“自定义XIB插座”?为什么这个问题被标记为“自定义控件”?是否有一些示例代码或图片可以帮助解释问题?


我用UICollectionViewCell的的方法是一样的,因为我使用的UITableViewCell - 参见教程 - http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html


更新:从您发布的评论的代码(不确定它是否完整),我认为这对你遵循这个教程很有用。有几个步骤可以完成,包括注册自定义类名并使用RegisterNibForCellReuse - 其中一个可能会为您解决这个问题。

+0

上面我已经更新了代码的片段。 – user2084102 2013-03-04 18:09:10

+0

编辑您的问题并在其中粘贴完整的代码 - 我无法在评论中阅读该代码。 – Stuart 2013-03-04 18:11:23

+0

我已经添加了this.tableComments.RegisterClassForCell。 \t \t \t this.tableComments.RegisterClassForCell(typeof(CustomCommentCell),commentCellId); – user2084102 2013-03-04 18:23:11

2

使用XIB创建Custom CollectionViewCell。执行以下操作

1)创建从UIcollectionViewCell

[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; 
     } 
    } 

} 

2继承C#类)添加IphoneView XIB文件具有相同的名称与在步骤创建的类的1

3)打开XIB在Xcode和做以下更改

enter image description here

3.1)选择FileOwner设置类相同的名称步骤1 enter image description here 3.2)选择视图设置类名称的UIView

4)设计你的XIB因此