C# UITableViewCell中的UITableView缺少事件
我实现了一个UITableView,其中包含一个自定义的UITableViewCell,其中包含一个UITableView,我能够正确绑定所有数据,但我缺少的是内部UITableView中没有触发的事件 基本上: 等等 内部UITableView内的滑动手势未触发,实际上未触发任何事件。我尝试过覆盖触摸事件,但没有命中。我尝试了很多没有用的事情,包括打电话给NextResponder touch events 包含外部UITableView的视图是可滚动的,可能与此有关 我想要实现的是,只有第2行被扫描,而不是整个内部UITableView。当从外部UITableView执行时,它可以工作,但这不是要求,因为第1行和第2行都被扫描,但是由于事件没有传递下来,我无法使它工作 我错过了什么 以下是我在外部UITableView自定义单元格内定义内部UITableView的方式:C# UITableViewCell中的UITableView缺少事件,c#,ios,uitableview,xamarin.ios,tableviewcell,C#,Ios,Uitableview,Xamarin.ios,Tableviewcell,我实现了一个UITableView,其中包含一个自定义的UITableViewCell,其中包含一个UITableView,我能够正确绑定所有数据,但我缺少的是内部UITableView中没有触发的事件 基本上: 等等 内部UITableView内的滑动手势未触发,实际上未触发任何事件。我尝试过覆盖触摸事件,但没有命中。我尝试了很多没有用的事情,包括打电话给NextResponder touch events 包含外部UITableView的视图是可滚动的,可能与此有关 我想要实现的是,只有第2
public PlanningGwWrapperCell(IntPtr handle) : base(handle)
{
_playersTable = new PlanningPlayersTableView();
_playersTableSource = new MvxPlanningGwPlayersTableViewSource(_playersTable);
_layout = CreateLayout();
_playersTable.Source = _playersTableSource;
_playersTable.Delegate = new PlanningGwPlayersTableDelegate();
ContentView.AddSubview(new UILayoutHost(_layout));
InitializeBindings();
_playersTable.ReloadData();
}
_布局是一种线性布局
UITableView就是这样的:
class PlanningPlayersTableView : UITableView
{
public PlanningPlayersTableView()
{
PrepareTable();
}
void PrepareTable()
{
SeparatorStyle = UITableViewCellSeparatorStyle.None;
RowHeight = Dimens.TableRowHeight;
ScrollEnabled = false;
BackgroundColor = Colors.AppBackground;
}
}
表格来源为:
public class MvxPlanningGwPlayersTableViewSource : BaseMvxTableViewSource<PlanningGwPlayersCell>
{
public MvxPlanningGwPlayersTableViewSource(UITableView tableView)
: base(tableView)
{
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return 1;
}
public override nint NumberOfSections(UITableView tableView)
{
return 1;
}
public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
{
var source = (MvxPlanningGwPlayersTableViewSource)tableView.Source;
var itemsSource = (source).ItemsSource;
if (itemsSource == null) return false;
var row = ((ObservableCollection<PlanningGWItemsViewModel>)itemsSource)[indexPath.Row];
return row.CanAdd || row.CanRemove;
}
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
{
switch (editingStyle)
{
case UITableViewCellEditingStyle.None:
break;
}
}
public override UITableViewCellEditingStyle EditingStyleForRow(UITableView tableView, NSIndexPath indexPath)
{
return UITableViewCellEditingStyle.Delete;
}
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
return (PlanningGwPlayersCell)tableView.DequeueReusableCell(PlanningGwPlayersCell.Id);
}
}
UILayoutHost正在吞并事件,如果我将表作为子视图直接放在其中,则会保留事件。答案确实是将标题行第一行拆分,并从UILayoutHost中滑动第二行:
public PlanningGwWrapperCell(IntPtr handle)
: base(handle)
{
...
ContentView.AddSubview(new UILayoutHost(_header));
ContentView.AddSubview(_playersTable);
InitializeBindings();
_playersTable.ReloadData();
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
_playersTable.Frame = new CGRect(0, Dimens.TableRowHeight, ContentView.Bounds.Width, Dimens.TableRowHeight);
_header.LayoutParameters = new LayoutParameters(ContentView.Bounds.Width, Dimens.TableRowHeight);
}
ContentView.AddSubview(new UILayoutHost(_layout));
public PlanningGwWrapperCell(IntPtr handle)
: base(handle)
{
...
ContentView.AddSubview(new UILayoutHost(_header));
ContentView.AddSubview(_playersTable);
InitializeBindings();
_playersTable.ReloadData();
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
_playersTable.Frame = new CGRect(0, Dimens.TableRowHeight, ContentView.Bounds.Width, Dimens.TableRowHeight);
_header.LayoutParameters = new LayoutParameters(ContentView.Bounds.Width, Dimens.TableRowHeight);
}