【发布时间】:2017-10-19 13:19:10
【问题描述】:
我尝试自定义UITableViewCell。我按照这里的解释做了:Xamarin Customizing a ViewCell
到目前为止一切顺利。 现在我尝试在 xib 中实现单元格的 ui。现在几乎可以工作了。我只有两个问题:
- 单元格的行高保持在 44。
- 如何访问标签等 ui 元素来更改其文本?
这是我的代码:
ViewCellRenderer:
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var NativeViewCell = (NativeViewCell)item;
cell = reusableCell as NativeiOSCell;
if (cell == null)
cell = new NativeiOSCell(item.GetType().FullName, NativeViewCell);
else
cell.NativeViewCell.PropertyChanged -= OnNativeViewCellPropertyChanged;
NativeViewCell.PropertyChanged += OnNativeViewCellPropertyChanged;
cell.UpdateCell(NativeViewCell);
tv.RowHeight = 102;
return cell;
}
NativeiOSCell:
public NativeiOSCell(string cellId, NativeViewCell cell) : base(UITableViewCellStyle.Default, cellId)
{
NativeViewCell = cell;
UITableViewCell view = (UITableViewCell) UINib.FromName("Layout1", NSBundle.MainBundle).Instantiate(null, null)[0];
this.Bounds = view.Bounds;
ContentView.AddSubviews(view.ContentView.Subviews);
}
【问题讨论】:
-
好的,我的第二个问题完成了。它们当然在子视图中,因此我可以从那里访问它们。
标签: c# uitableview xamarin xamarin.ios xamarin.forms