2016-11-22 10 views
0

IUITableViewDataSourceインターフェイスを使用して、(tableviewデータソースとデリゲートのための別のクラスを作成する代わりに)単一クラスでマルチセクションtableviewを実装しようとしています。しかし、NumberOfSectionsメソッドが呼び出されていません。 私のビューコントローラのコードは次のようになります。NumberOfSectionsがIUITableViewDataSourceで動作しないXamarin

public partial class ViewController : UIViewController, IUITableViewDelegate, IUITableViewDataSource 
    { 

     public ViewController(IntPtr handle) : base(handle) 
     { 
     } 

     public override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 

      tableView.WeakDataSource = this; 
      tableView.DataSource = this; 
     } 

     public override void DidReceiveMemoryWarning() 
     { 
      base.DidReceiveMemoryWarning(); 
      // Release any cached data, images, etc that aren't in use.  
     } 

     public nint NumberOfSections(UITableView tableView) 
     { 
      return 5; 
     } 

     public nint RowsInSection(UITableView tableview, nint section) 
     { 
      return 4; 
     } 

     public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
     { 
      UITableViewCell cell = tableView.DequeueReusableCell("Cell"); 
      cell.TextLabel.Text = "Row " + indexPath.Row + " Section " + indexPath.Section; 

      return cell; 
     } 


    } 

私はUITableViewSourceサブクラスを作成し、実装と間違っている何

tableView.Source = new TableSource(); 

のように割り当てた場合、これは完全にウォーキングか?

答えて

0

テーブルは、TableSourceのインスタンスを作成するときにのみロードされます。 このコードをviewDidLoadに追加

table = new UITableView(View.Bounds); // defaults to Plain style 
    table.Source = new TableSource(tableItems); 
    Add (table); 
+0

私のテーブルの行は大丈夫です。私はストーリーボードからtableviewをロードしています – Johnykutty

関連する問題