【发布时间】:2016-11-22 19:26:48
【问题描述】:
我正在尝试使用IUITableViewDataSource 接口实现具有单个类的多节表视图(而不是为表视图数据源和委托创建单独的类)。但是NumberOfSections 方法没有被调用。
我的视图控制器代码如下所示:
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();
实施有什么问题?
【问题讨论】:
标签: ios uitableview xamarin.ios