2014-09-02 45 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;