Arv*_*vis 3 uitableview xamarin.ios ios xamarin
我使用Xamarin iOS设计器为我的TableView设计自定义TableViewCell类.但是除了单元本身之外,所有单元子视图属性(出口)都返回null.
我的自定义单元类:
partial class VehiclesTableCell : UITableViewCell
{
public VehiclesTableCell(IntPtr handle) : base(handle) { }
public void UpdateCell(string licensePlate) {
licensePlateLabel.Text = licensePlate; //hit the null reference exception for licensePlateLabel
}
}
Run Code Online (Sandbox Code Playgroud)
生成的部分类:
[Register ("VehiclesTableCell")]
partial class VehiclesTableCell
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel licensePlateLabel { get; set; }
void ReleaseDesignerOutlets ()
{
if (licensePlateLabel != null) {
licensePlateLabel.Dispose ();
licensePlateLabel = null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
和我的Table Source类的GetCell:
public class VehiclesTableSource : UITableViewSource
{
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) {
// Dequeueing the reuse cell
var cell = (VehiclesTableCell)tableView.DequeueReusableCell(new NSString(typeof(VehiclesTableCell).Name));
// Set cell properties
cell.UpdateCell(LicensePlate);
// Return the cell with populated data
return cell;
}
}
Run Code Online (Sandbox Code Playgroud)
我们看到genereted代码有licensePlate的出口,那么为什么它的属性为null?故事板是不是应该自动实例化其所有子视图?至少它发生在所有其他情况.

我的习惯遇到了同样的问题TableViewCell.我发现问题在于TableView.RegisterClassForCellReuse (typeof(MyCell), MyCellId).我必须将其更改为TableView.RegisterNibForCellReuse(UINib.FromName("MyCell", NSBundle.MainBundle), MyCellId)以便加载我的.xib.
| 归档时间: |
|
| 查看次数: |
1982 次 |
| 最近记录: |