2016-08-12 8 views
0

私はxamarinのIOSコードから始まって、C#にはまったく新しいです。私は基本的にネイティブアプリの背景からです。 xamarinでswTableViewコントローラを使用して、以下のようにテーブルを表示する方法を示す簡単なアプリが必要でした。Xamarin IOSでswTableViewを使用する方法。

のように:事前に

ColumnNam ColumnNam ColumnNam ColumnNam 
data1  data2  data3  data4 
data5  data6  data7  data8 

私は、例えば、検索を試みたが、いずれかが既に私に知らせてください情報を持っている場合、私は... 1を見つけられませんでした。..

Thxを

答えて

0

システムコントロールが必要なような効果を発揮することはありませんが、カスタマイズする必要があります。参考のためにサンプルを書く:

In ViewController.cs:

public override void ViewDidLoad() 
    { 
     this.Title = "testTalbeView"; 
     this.View.Frame = UIScreen.MainScreen.Bounds; 
     this.View.BackgroundColor = UIColor.White; 

     UITableView tableView = new UITableView (UIScreen.MainScreen.Bounds); 
     tableView.SeparatorStyle = UITableViewCellSeparatorStyle.None; 
     tableView.Source = new MyTableSource(); 
     this.Add (tableView); 
    } 

MyTableSource.cs:

public class MyTableSource : UITableViewSource 
{ 
    private string cellID = "MyCell"; 
    private int columns = 2; 
    private List<string> dataList; 

    public MyTableSource() 
    { 
     dataList = new List<string>(); 
     for (int i = 0; i < 10; i++) { 
      dataList.Add ("data " + i.ToString()); 
     } 
    } 

    #region implemented abstract members of UITableViewSource 

    public override nint RowsInSection (UITableView tableview, nint section) 
    { 
     return dataList.Count/columns + 1; 
    } 

    public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath) 
    { 
     MyCell cell = tableView.DequeueReusableCell (cellID) as MyCell; 
     if (null == cell) { 
      cell = new MyCell (UITableViewCellStyle.Default, cellID); 
      cell.TextLabel.TextAlignment = UITextAlignment.Center; 
     } 

     int row = (int)indexPath.Row; 
     if (0 == row) { 
      cell.SetData ("Column0", "Column1"); 
     } 
     else{ 
      cell.SetData (dataList [(row-1) * columns], dataList [(row-1) * columns + 1]); 
     } 
     return cell; 
    } 

    #endregion 
} 

MyCell.cs:

effect image

がそれを願っています:

public class MyCell : UITableViewCell 
{ 
    private UILabel lbC0; 
    private UILabel lbC1; 

    public MyCell (UITableViewCellStyle style,string cellID):base(style,cellID) 
    { 
     lbC0 = new UILabel(); 
     lbC0.TextAlignment = UITextAlignment.Center; 
     this.AddSubview (lbC0); 

     lbC1 = new UILabel(); 
     lbC1.TextAlignment = UITextAlignment.Center; 
     this.AddSubview (lbC1); 
    } 

    public void SetData(string str0,string str1) 
    { 
     lbC0.Text = str0; 
     lbC1.Text = str1; 
    } 

    public override void LayoutSubviews() 
    { 
     nfloat lbWidth = this.Bounds.Width/2; 
     nfloat lbHeight = this.Bounds.Height; 
     lbC0.Frame = new CoreGraphics.CGRect (0, 0, lbWidth, lbHeight); 
     lbC1.Frame = new CoreGraphics.CGRect (lbWidth, 0, lbWidth, lbHeight); 
    } 
} 

その後は、画像のようにtableViewを得ることができますできる 助けます。

関連する問題