C# 用to信息填充表
我想把arrayVariable1放在上面,第二个放在下面 我使用命令:C# 用to信息填充表,c#,ios,uitableview,xamarin,C#,Ios,Uitableview,Xamarin,我想把arrayVariable1放在上面,第二个放在下面 我使用命令: public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell (cellID); if (cell == null
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell (cellID);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Subtitle, cellID);
}
cell.TextLabel.Text = ArrayVariable1;
cell.TextLabel.Text = ArrayVariable2;
return cell;
}
但是如果我运行它,变量1不会出现,只有变量2。您在cell.textlab.Text的第二个赋值中覆盖了您自己
cell.TextLabel.Text = ArrayVariable1;
cell.TextLabel.Text = ArrayVariable2; <-- this overwrites the line above this.
但是如果你真的想要的不仅仅是一个连接,你就必须为你的单元格创建一个自定义的布局,并将其膨胀。看看它的外观/
对于不同的表格类型和使用标题、副标题等,我认为这是您可能需要的,如果不需要,您可以始终创建自己的单元格类型。您正在使用ArrayVariable2覆盖TextLabel。使用cell.textlab.Text=ArrayVariable1设置它,然后使用cell.textlab.Text=ArrayVariable2覆盖它。如果要将两个数组变量中的数据打包到标签(最好是UITextView)中,则可以执行以下操作:
cell.TextLabel.Text = [NSString stringWithFormat:@"%@\n%@", ArrayVariable1, ArrayVariable2];
您需要确保将标签设置为多行(即2行)样式为
UITableViewCellStyle的UITableViewCell
。Subtitle
具有两种不同的标签属性TextLabel
是上标签,DetailTextLabel
是下标签
cell.TextLabel.Text = ArrayVariable1;
cell.DetailTextLabel.Text = ArrayVariable2;
cell.TextLabel.Text = ArrayVariable1;
cell.DetailTextLabel.Text = ArrayVariable2;