缺少 UITableViewCell 事件中的 UITableView

UITableView within a UITableViewCell events missing

我已经实现了一个 UITableView,其中包含一个自定义 UITableViewCell,里面有一个 UITableView,我能够正确绑定我的所有数据,但我缺少的是事件没有在我内心 UITableViews.

中触发

基本上:

outer UITableView
----custom cell
---- ---- ----inner UITableView #1
---- ---- ---- ----custom cell with two rows, row#1 with labels
---- ---- ---- ----custom cell with two rows, row#2 with swipe gesture
----custom cell
---- ---- ----inner UITableView #2
---- ---- ---- ----custom cell with two rows, row#1 with labels
---- ---- ---- ----custom cell with two rows, row#2 with swipe gesture
----custom cell
---- ---- ----inner UITableView #3
---- ---- ---- ----custom cell with two rows, row#1 with labels
---- ---- ---- ----custom cell with two rows, row#2 with swipe gesture

等...

内部 UITableView 内的滑动手势没有被触发,实际上没有事件被触发。我试过覆盖触摸事件,但没有被击中。我尝试了很多方法都无济于事,包括调用 NextResponder 触摸事件。

包含外部 UITableView 的视图是可滚动的,也许这与它有关?

我想要实现的是只有第 2 行被刷过,而不是整个内部 UITableView(从外部 UITableView 完成时它可以工作,但这不是必需的,因为两行#1 和 #2 滑动)但是由于事件没有传递下来,我无法让它工作。

我错过了什么?

这就是我在外部 UITableView 自定义单元格中定义内部 UITableView 的方式:

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();
}

_layout 是一个 LinearLayout (XibFree)。

UITableView 就是这样:

class PlanningPlayersTableView : UITableView
{
    public PlanningPlayersTableView()
    {
        PrepareTable();
    }

    void PrepareTable()
    {
        SeparatorStyle = UITableViewCellSeparatorStyle.None;
        RowHeight = Dimens.TableRowHeight;
        ScrollEnabled = false;
        BackgroundColor = Colors.AppBackground;
    }
}

table 来源是:

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);
    }
}

那么关于如何传承事件的任何线索?外部 table 能否仅响应滚动事件而所有其他事件都由内部 table 处理?

更新
结果发现问题与以下行有关:

ContentView.AddSubview(new UILayoutHost(_layout));

UILayoutHost 正在吞噬事件,如果我将 table 直接放在里面作为子视图,事件将被保留。

答案确实是从 UILayoutHost 拆分 header 行(第一行)和滑动行(第二行):

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);
    }