【发布时间】:2017-07-12 15:47:43
【问题描述】:
在我正在开发的应用程序中,需要自定义 UITableView 部分页眉和页脚。为此,我想创建一个与绑定和我们的逻辑一起使用的自定义控件。
为此,我创建了一个 XIB 并添加了一个如下所示的支持类:
public partial class HeaderFooterView : MvxTableViewHeaderFooterView
{
public static readonly NSString Key = new NSString("HeaderFooterView");
public static readonly UINib Nib = UINib.FromName("HeaderFooterView", NSBundle.MainBundle);
public HeaderFooterView(IntPtr handle) : base(handle)
{
}
public override void AwakeFromNib()
{
base.AwakeFromNib();
//var binding = this.CreateBindingSet<HeaderFooterView, TableViewSection>();
//binding.Apply();
}
}
MvxTableViewHeaderFooterView 实际上是一个非常简单的类,将股票UITableViewHeaderFooterView 与IMvxBindable 组合在一起。没什么特别的。
但是由于某种原因,即使我在 TableViewSource 构造函数中正确注册了它:
tableView.RegisterNibForHeaderFooterViewReuse(HeaderFooterView.Nib, HeaderFooterView.Key);
并且只返回 Header 本身的正确方法:
public override UIView GetViewForHeader(UITableView tableView, nint section)
{
return tableView.DequeueReusableHeaderFooterView(HeaderFooterView.Key);
}
应用程序因以下错误而死:
2017-07-12 16:56:40.517 MyAppiOS[3833:58706] *** Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UITableView.m:6696
2017-07-12 16:56:40.528 MyAppiOS[3833:58706] WARNING: GoogleAnalytics 3.17 void GAIUncaughtExceptionHandler(NSException *) (GAIUncaughtExceptionHandler.m:48): Uncaught exception: invalid nib registered for identifier (HeaderFooterView) - nib must contain exactly one top level object which must be a UITableViewHeaderFooterView instance
我的 NIB 实际上包含一个根对象,即根视图本身,它被设置为 HeaderFooterView 类(它派生自 MvxTableViewHeaderFooterView,而 UITableViewHeaderFooterView 又派生自 UITableViewHeaderFooterView)。然而它声称没有 UITableViewHeaderFooterView 实例。
为什么它没有按预期工作?
【问题讨论】:
-
我相信你必须为页脚/页眉分配一个估计的高度,否则它不会正确呈现。
-
我的问题不是它没有渲染,而是当我尝试调用
DequeueReusableHeaderFooterView时应用程序崩溃了。
标签: ios xamarin.ios mvvmcross nib uitableviewsectionheader