UITableView在UITableViewCell事件中丢失
问题描述:
我已经实现了一个UITableView
,其中包含一个内部为UITableView
的自定义UITableViewCell
,我能够正确绑定所有数据,但是我错过的是未在我的内部激发的事件UITableViews
。UITableView在UITableViewCell事件中丢失
基本上是:
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;
}
}
表来源:
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);
}
}
那么如何传承的事件任何线索?外部表可以只响应滚动事件,而所有其他事件由内部表处理吗?
UPDATE
原来,问题有以下行做:
ContentView.AddSubview(new UILayoutHost(_layout));
的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);
}