2014-09-02 65 views
0

我想将arrayVariable1放在顶部和第二个下面。填充表格以提供信息

我用命令:

  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

回答

2

你自己覆盖在第二分配cell.TextLabel。文字

cell.TextLabel.Text = ArrayVariable1; 
cell.TextLabel.Text = ArrayVariable2; <-- this overwrites the line above this. 

一个非常简单的解决方案...

cell.TextLabel.Text = string.Format("{0} {1}", ArrayVariable1, ArrayVariable2); 

但是,如果您真的不仅仅需要连接,还需要为单元创建自定义布局并将其膨胀。

0

您正在用ArrayVariable2覆盖TextLabel。你用cell.TextLabel.Text = ArrayVariable1来设置它,然后用cell.TextLabel.Text = ArrayVariable2覆盖它。如果你想从两个数组变量的数据打包成一个标签(或更好的UITextView的),那么你可以这样做:

cell.TextLabel.Text = [NSString stringWithFormat:@"%@\n%@", ArrayVariable1, ArrayVariable2]; 

你需要确保你的标签设置为多行(即2行)

0

样式UITableViewCellStyle.Subtitle的A UITableViewCell具有两种不同的标签属性。 TextLabel是上标签,DetailTextLabel是下标签

 cell.TextLabel.Text = ArrayVariable1; 
     cell.DetailTextLabel.Text = ArrayVariable2;