C# 在Xamarin iOS中以编程方式设置UITableViewCell样式
我知道可以在iOS Designer中设置样式,但如何在代码中设置呢 通常,您使用此功能请求单元格C# 在Xamarin iOS中以编程方式设置UITableViewCell样式,c#,ios,uitableview,xamarin.ios,xamarin,C#,Ios,Uitableview,Xamarin.ios,Xamarin,我知道可以在iOS Designer中设置样式,但如何在代码中设置呢 通常,您使用此功能请求单元格 var cell = tableView.DequeueReusableCell (cellIdentifier); 我看到Objective-C解决方案创建了一个新单元。在新范例之后,如果使用RegisterClassForCellReuse,则不需要创建新的单元格 这是在代码中设置样式的唯一方法吗 if (cell == null) { cell = new UITableViewC
var cell = tableView.DequeueReusableCell (cellIdentifier);
我看到Objective-C解决方案创建了一个新单元。在新范例之后,如果使用RegisterClassForCellReuse,则不需要创建新的单元格
这是在代码中设置样式的唯一方法吗
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellIdentifier);
}
发件人:
如果您使用RegisterClassForCellReuse,我认为您必须使用一个自定义单元格,它将UITableViewCell子类化。否则,它将使用默认样式创建标准单元
通过在ViewDidLoad中注册类,可以实现以下功能:
以及将UITableViewCell子类化。[Export]属性是必需的:
public class SubtitleTableViewCell : UITableViewCell
{
[Export("initWithStyle:reuseIdentifier:")]
public SubtitleTableViewCell(UITableViewCellStyle style, string cellId)
: base( UITableViewCellStyle.Subtitle, cellId) { }
}
public class SubtitleTableViewCell : UITableViewCell
{
[Export("initWithStyle:reuseIdentifier:")]
public SubtitleTableViewCell(UITableViewCellStyle style, string cellId)
: base( UITableViewCellStyle.Subtitle, cellId) { }
}