【发布时间】:2017-05-04 11:14:07
【问题描述】:
所以这是我第一次使用 Xamarin Forms TextCell。我希望单元格的 Detail 文本出现在右侧的 Disclosure 图标旁边,如下图所示。
PS:图片不是我的。
我已尝试搜索此内容,但找不到任何参考。有谁知道我该怎么做?
【问题讨论】:
标签: c# xamarin.ios xamarin.forms
所以这是我第一次使用 Xamarin Forms TextCell。我希望单元格的 Detail 文本出现在右侧的 Disclosure 图标旁边,如下图所示。
PS:图片不是我的。
我已尝试搜索此内容,但找不到任何参考。有谁知道我该怎么做?
【问题讨论】:
标签: c# xamarin.ios xamarin.forms
原生 iOS 单元格有一个 UITableViewCellStyle (documentation),您可以通过实现 custom renderer 来设置它。
这应该看起来像这样:
[assembly: ExportRenderer (typeof (TextCell), typeof (RightDetailSample.iOS.TextCellRenderer))]
namespace RightDetailSample.iOS
{
public class TextCellRenderer : Xamarin.Forms.Platform.iOS.TextCellRenderer
{
public override UITableViewCell GetCell (Cell item, UITableViewCell reusableCell, UITableView tv)
{
var textCell = (TextCell)item;
var fullName = item.GetType ().FullName;
var cell = tv.DequeueReusableCell (fullName) as CellTableViewCell;
if (cell == null) {
cell = new CellTableViewCell (UITableViewCellStyle.Value1, fullName);
} else {
cell.Cell.PropertyChanged -= cell.HandlePropertyChanged;
}
cell.Cell = textCell;
textCell.PropertyChanged += cell.HandlePropertyChanged;
cell.PropertyChanged = this.HandlePropertyChanged;
cell.TextLabel.Text = textCell.Text;
cell.DetailTextLabel.Text = textCell.Detail;
UpdateBackground (cell, item);
return cell;
}
}
}
注意您如何在新单元格的构造函数中设置UITableViewCellStyle.Value1。之后无法设置。实现后如下所示:
可以在here找到一个示例项目。
【讨论】:
TextCell 在其详细信息下具有静态格式标题,如果您想进行自定义单元格设计,您应该使用Custom Cell
【讨论】: