UITableView行滑动操作不适用于XamarinSidebar

时间:2017-08-21 11:14:14

标签: xamarin xamarin.ios mvvmcross

我正在使用带有XamarinSidebar的xamarin.ios,但我在EditActionsForRow事件中遇到MvxTableViewSource问题,如果我不使用XamarinSidebar进行演示,例如以模态显示,它会完美地检测到事件,并且向我展示了内容,但是如果我用XamarinSidebar显示它并没有检测到水平滑动。

CustomViewController:

[MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.ResetRoot, true, MvxSplitViewBehaviour.Detail)]
public partial class CustomViewController : MvxViewController<CustomViewModel>
{
    public CustomViewController() : base("CustomViewController", null)
    {

    }
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var set = this.CreateBindingSet<CustomViewController, CustomViewModel>();

        var source = new TableViewSource(TableView);
        set.Bind(source).For(s => s.ItemsSource).To(vm => vm.CustomList);
        TableView.Source = source;


        set.Apply();

    }
}

和TableViewSource:

public class TableViewSource : MvxTableViewSource
{
    public List<CustomItems> TableItems { get { return ItemsSource as List<CustomItems>; } }


    string CellIdentifier = "CustomCell";

    public ChatContactTableViewSource(UITableView tableView) : base(tableView)
    {

    }

    public override nint RowsInSection(UITableView tableview, nint section)
    {
        return TableItems.Count;

    }

    public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
    {
        Contact item = TableItems[indexPath.Row];
        Console.WriteLine("Item selected: " + item.ContactName);
    }

    public override UITableViewRowAction[] EditActionsForRow(UITableView tableView, NSIndexPath indexPath)
    {
        List<UITableViewRowAction> items = new List<UITableViewRowAction>();

        //Button
        var Button = UITableViewRowAction.Create(UITableViewRowActionStyle.Normal, "Delete",
            delegate
            {
                Console.WriteLine("DeleteButton");
            });


        Button.BackgroundColor = UIColor.Red;
        items.Add(Button);

        //I have more than one button here

        return items.ToArray();
    }

    public override bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
    {
        return true;
    }

    public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
    {
        Console.WriteLine("EDITING STYLE");
        if (editingStyle == UITableViewCellEditingStyle.Delete)
        {
            TableItems.RemoveAt(indexPath.Row);
        }
    }

    protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
    {
        var cell = tableView.DequeueReusableCell(CellIdentifier) as CustomCell;
        CustomItems ItemCustom = TableItems[indexPath.Row];

        //---- if there are no cells to reuse, create a new one
        if (cell == null)
        {
            cell = CustomCell.Create();
        }
        cell.LabelText.Text = ItemCustom.Name;
        return cell;
    }
}

解决了实施问题:

public class BaseMenuViewController<TViewModel> : BaseMenuView<TViewModel>, IMvxSidebarMenu where TViewModel : class, IMvxViewModel
{
    public virtual UIImage MenuButtonImage => UIImage.FromBundle("threelines");

    public virtual bool AnimateMenu => true;
    public virtual float DarkOverlayAlpha => 0.7f;
    public virtual bool HasDarkOverlay => true;
    public virtual bool HasShadowing => false;
    public virtual bool DisablePanGesture => true; //Here the solution
    public virtual bool ReopenOnRotate => true;

    private int MaxMenuWidth = 304;
    private int MinSpaceRightOfTheMenu = 55;

    public int MenuWidth => UserInterfaceIdiomIsPhone ?
    int.Parse(UIScreen.MainScreen.Bounds.Width.ToString()) - MinSpaceRightOfTheMenu : MaxMenuWidth;

    private bool UserInterfaceIdiomIsPhone
    {
        get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
    }

    public virtual void MenuWillOpen()
    {
    }

    public virtual void MenuDidOpen()
    {
    }

    public virtual void MenuWillClose()
    {
    }

    public virtual void MenuDidClose()
    {
    }
}

0 个答案:

没有答案