因此,这是我的安全代码:
TableView.TableHeaderView = headerLearning;
TableView.TableFooterView = headerFinished;
到 TableHeaderView 的行(字段)设置确定。无论如何,我无法将其设置为 TableFooterView 。
在对断点进行了一些研究之后,我注意到
TableView.TableHeaderView = headerLearning;
程序转到覆盖nint RowsInSection ...
但之后不会
TableView.TableFooterView = headerFinished;
答案 0 :(得分:0)
使用
应该可以 TableView.TableFooterView = headerFinished;
我为您编写了一个简单的示例,它适用于页眉和页脚:
public partial class ViewController : UIViewController
{
UITableView table;
public ViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
table = new UITableView(View.Bounds); // defaults to Plain style
string[] tableItems = new string[] { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
table.Source = new TableSource(tableItems);
Add(table);
UIView headV = new UIView();
headV.Frame = new CoreGraphics.CGRect(0,0,100,50);
headV.BackgroundColor = UIColor.Red;
UIView footV = new UIView();
footV.Frame = new CoreGraphics.CGRect(0, 0, 100, 50);
footV.BackgroundColor = UIColor.Green;
table.TableHeaderView = headV;
table.TableFooterView = footV;
}
public override void DidReceiveMemoryWarning ()
{
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
}
public class TableSource : UITableViewSource
{
string[] TableItems;
string CellIdentifier = "TableCell";
public TableSource(string[] items)
{
TableItems = items;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return TableItems.Length;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
string item = TableItems[indexPath.Row];
//---- if there are no cells to reuse, create a new one
if (cell == null)
{ cell = new UITableViewCell(UITableViewCellStyle.Default, CellIdentifier); }
cell.TextLabel.Text = item;
return cell;
}
}
您是否将框架设置为headerFinished
?分享有关tablview的更多代码,我们可以为您提供更好的帮助。
如果要使用 section-header 和 section-footer ,可以查看此文档:adding-headers-and-footers