【问题标题】:NumberOfSections not working with IUITableViewDataSource XamarinNumberOfSections 不适用于 IUITableViewDataSource Xamarin
【发布时间】: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


    【解决方案1】:

    只有在您创建 TableSource 的实例时才会加载该表。 将此代码添加到 viewDidLoad

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

    【讨论】:

    • 但是我的表格行没问题,我正在从情节提要加载表格视图
    猜你喜欢
    • 2020-02-07
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 2016-09-29
    • 2020-03-14
    相关资源
    最近更新 更多