2016-08-12 3 views
0

저는 C#을 처음 접했고 xamarin IOS 코드로 시작했습니다. 기본적으로 네이티브 앱 배경입니다. xamarin에서 swTableView 컨트롤러를 사용하여 아래에 언급 된 표를 표시하는 방법을 보여주는 간단한 앱이 필요했습니다.Xamarin IOS에서 swTableView를 사용하는 방법.

등 :

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

나는 예를 들어 검색을 시도하지만 난 사전에 .. 하나는 이미 정보가 있으면 알려 주시기 바랍니다 ...

들으을 하나를 찾을 수 없습니다

답변

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를 얻을 수 있습니다 할 수있다 도와주세요.

관련 문제