我创建了一个简单的视图控制器,其中包含一个表格视图。我随后创建了一个.xib文件来设计将放入表格中的UITableViewCells。
无论我尝试什么,GetCell都无法找到UITableViewCell Nib。我已经尝试了所有名称/ ID和类型转换的变化。作为Xamarin和C#的新手,我可能漏掉了一些简单的东西。
视图控制器:
注:本文涉及IT技术相关内容。
无论我尝试什么,GetCell都无法找到UITableViewCell Nib。我已经尝试了所有名称/ ID和类型转换的变化。作为Xamarin和C#的新手,我可能漏掉了一些简单的东西。
视图控制器:
public partial class ScheduleViewController : BaseViewController<ScheduleViewModel>
{
[Export("initWithBundle:owner:extras:")]
public ScheduleViewController(NSBundle bundle, UIViewController owner, string extras) : base("ScheduleViewController", bundle, owner, extras)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
Dictionary<string, List<string>> itemData = new Dictionary<string, List<string>>()
{
{"phones", new List<string>() {
"Android",
"iOS",
"Windows Phone",
"Other",
"The Thing"
}},
{"computers", new List<string>() {
"osx",
"windows",
"linux"
}}
};
UITableView table = new UITableView(View.Bounds);
table.Source = new ScheduleTableViewSource(itemData);
table.SeparatorStyle = UITableViewCellSeparatorStyle.None;
Add(table);
}
UITableVIewCell类:
public partial class WorkCell : UITableViewCell
{
public static readonly NSString Key = new NSString("WorkCell");
public static readonly UINib Nib;
static WorkCell()
{
Nib = UINib.FromName("WorkCell", NSBundle.MainBundle);
}
protected WorkCell(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
}
WorkCell .xib文件
TableViewDataSource:
注:本文涉及IT技术相关内容。
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
// always null
UINib nib = UINib.FromName("WorkCellContainer", NSBundle.MainBundle);
tableView.RegisterNibForCellReuse(nib, "workItemCell");
var cell = (WorkCell)tableView.DequeueReusableCell ("workItemCell");
return cell;
}