【发布时间】:2013-05-02 23:21:31
【问题描述】:
我在我的项目中创建了一个自定义UITableViewController、Cell 和 Source。 Controller 和 Cell 最初是作为 iPhone UIViewController 模板创建的,因此我将部分类与 XIB 文件配对。我有相同的设置已经在使用另一个表,并且我遵循相同的过程(我认为)来创建这个,这就是为什么我不知道为什么会收到这个错误。
这是我在TableViewSource 类中的GetCell
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 内的 UILabel。我正在尝试在 IB 中玩一些东西,但如果你第一次没有正确地做到这一点,那可能会非常令人气愤。希望有人能认识到这个错误并纠正我。
编辑
在没有找到答案的情况下,我选择避免从笔尖加载,并对我的代码进行了以下更改:
MyTableViewSource 中的新 Get Cell 方法
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);
}
希望这可以帮助那里的人:)
【问题讨论】:
标签: ios uitableview xamarin.ios xib iboutlet