未调用GetHeightForHeader和GetViewForHeader [英] GetHeightForHeader and GetViewForHeader not called

查看:162
本文介绍了未调用GetHeightForHeader和GetViewForHeader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个包含两个部分的tableview。我想在第二部分标题中添加一个headerView。

I am working on a tableview which has two sections. And I would like to add a headerView in the second section header.

我已经实现了以下代码。它调用 TitleForHeader 但很遗憾, GetHeightForHeader GetViewForHeader 都没有完全叫了。任何人都有任何线索?

I have implemented the following code. It calls TitleForHeader but unfortunately neither GetHeightForHeader nor GetViewForHeader are getting called at all. Anyone has any clue?

public override string TitleForHeader (UITableView tableView, nint section)
{
   if (section == 0)
   {
     return "Details";
   }
   if (section == 1)
   {
     return "Settings";
   }

 return "";
}

public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
    if (section == 0)
    {
       return 0.0001f;
    }
    if (section == 1) 
    {
        return 100.0f;
    }
  return UITableView.AutomaticDimension;
}

public override UIView GetViewForHeader(UITableView tableView, nint section)
{
  if (section == 1) {
    UIView headerView = new UIView (new CGRect (0, 0, (float)tableView.Bounds.Width, (float)tableView.SectionHeaderHeight));
    headerView.BackgroundColor = UIColor.Black;
    return headerView;
   }
   else {
      return null;
   }
}


推荐答案

我有同样的问题刚才意识到我正在设置委托和源代码如下:

I had the same problem just realised I was setting the delegate and the source like so:

Table.Delegate = new TableDelegate(this); //remove this bit
Table.Source = new TableSource<string>(list, Table);

我意识到我应该只使用UITableViewSource而不设置两者。

I realised that I should be using only UITableViewSource and not setting both.


UITableViewSource 替换以下两个类,这些类在Xamarin.iOS中仍然可用,但通常不需要:

UITableViewSource replaces the following two classes, which are still available in Xamarin.iOS but are not normally required:

UITableViewDataSource - 在Xamarin.iOS中作为抽象类建模的Objective-C协议。必须进行子类化以提供包含每个单元格视图的表格,以及有关页眉,页脚以及表格中行和部分数量的信息。

UITableViewDataSource – An Objective-C protocol that is modeled in Xamarin.iOS as an abstract class. Must be subclassed to provide a table with a view for each cell, as well as information about headers, footers and the number of rows and sections in the table.

UITableViewDelegate - 在Xamarin.iOS中作为类建模的Objective-C协议。处理选择,编辑功能和其他可选表格功能。

UITableViewDelegate – An Objective-C protocol that is modeled in Xamarin.iOS as a class. Handles selection, editing features and other optional table features.

Xamarin docs

我刚把行选的方法移到我的 TableSource ,它现在调用 TitleForHeader GetViewForHeader 方法(它们不是相互排斥的,只有 设置来源没有委托。

I just moved my rowselected method into my TableSource and it now calls the TitleForHeader and GetViewForHeader methods (they are not mutually exclusive) and only set the source no delegate.

这篇关于未调用GetHeightForHeader和GetViewForHeader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆