0

我在我的项目中创建了一个 custom UITableViewController、 Cell 和 Source 。Controller 和 Cell 最初是作为 iPhone UIViewController 模板创建的,因此我将部分类与 XIB 文件配对。我已经使用相同的设置与另一个表一起工作,并且我遵循相同的过程(我认为)来创建这个,这就是为什么我不知道为什么会收到此错误。

这是我GetCellTableViewSource课堂上

public override UITableViewCell GetCell (UItableView tv, NSIndexPath path)
{
    MyCell oCell;
    NSArray oViews;
    //
    oCell = tv.DequeueReusableCell ("MyCell") as MyCell;
    //
    if (oCell == null)
    {
        oViews = NSBundle.MainBundle.LoadNib ("MyCell", tv, null);
        oCell = Runtime.GetNSObject (oViews.ValueAt (0)) as MyCell;
    }
    //
    oCell.UpdateWithData (MyDataCollection[path.Row]);
    //
    return oCell;
}

我在尝试加载笔尖的行出现异常:

抛出 Objective-C 异常。名称:NSUnknownKeyException 原因:[ setValue:forUnidentifiedKey:]:此类与键 lbl_address 的键值编码不兼容。

我在想这指的是 IB 中的一个问题,我在其中创建了单元格接口,lbl_address就像UITableViewCell. 我正在尝试在 IB 中玩一些东西,但如果你第一次没有正确地做到这一点,那可能会非常令人气愤。希望有人会认识到这个错误并纠正我。

编辑

在没有找到答案的情况下,我选择避免从笔尖加载,并对我的代码进行了以下更改:

Get Cell方法在MyTableViewSource

public override UITableViewCell GetCell (UITableView tv, NSIndexPath path)
{
    MyCell oCell;
    //
    oCell = tv.DequeueReusableCell ("MyCell") as MyCell;
    //
    if (oCell == null)
        oCell = new MyCell ("MyCell");
    //
    oCell.UpdateWithData (MyDataCollection[path.Row]);
    //
    return oCell;
}

新的构造函数MyCell

public MyCell (string sIdentifier)
    : base (UITableViewCellStyle.Default, sIdentifier)
{
    // Set up the contents of the cell in the absence of loading from the nib
    txt_name = new UILabel ()
    {
        Font = UIFont.SystemFontOfSize (15),
        TextColor = UIColor.LightGray
    };
    img_profile = new UIImageView ();
    //
    // Make sure to add the controls to the content view!
    ContentView.Add (txt_name);
    ContentView.Add (img_profile);
}

希望这可以帮助那里的人:)

4

1 回答 1

0

这通常是由于一个元素已被删除,但 xib 中的先前连接出口仍然有效。

我会尝试以下步骤。

打开xib。右键单击单元格。如果您在该键名附近看到黄色警告,请将其删除(x 按钮)。

让我知道这是否可以解决问题。

于 2013-05-11T13:04:38.700 回答