【问题标题】:MVVMCross iOS table view cell bindingMVVMCross iOS 表格视图单元格绑定
【发布时间】:2017-10-30 03:02:39
【问题描述】:

我是 iOS 的 MVVMCross 模型的新手。我想处理 tableview 单元格点击,并获取点击的单元格索引。但我不知道如何访问索引。

这是我的查看代码。

        var menuSource = new MenuTableViewSource(menuTableView, MenuCell.Key, MenuCell.Key);
        this.menuTableView.Source = menuSource;

        var set = this.CreateBindingSet<BooksView, BooksViewModel>();
        set.Bind(menuSource).To(vm => vm.MenuCellTexts);
        set.Bind(menuSource).For(s => s.SelectionChangedCommand).To(vm => vm.ItemSelectedCommand);
        set.Apply();

这是我的 ViewModel 代码。

    private MvxCommand _itemSelectedCommand;
    public MvxCommand ItemSelectedCommand
    {
        get
        {
            _itemSelectedCommand = _itemSelectedCommand ?? new MvxCommand(DoSelectedItem);
            return _itemSelectedCommand;
        }
    }

    private void DoSelectedItem()
    {
        // How to get the tapped cell index here??
    }

【问题讨论】:

    标签: xamarin xamarin.ios mvvmcross


    【解决方案1】:

    您可以尝试通过将选定的行对象传递给您的Command 来查找索引,如下所示:

    private MvxCommand<YourClassName> _itemSelectedCommand;
    public MvxCommand<YourClassName> ItemSelectedCommand
    {
        get
        {
            _itemSelectedCommand = _itemSelectedCommand ?? new MvxCommand(DoSelectedItem);
            return _itemSelectedCommand;
        }
    } 
    
    private void DoSelectedItem(YourClassName item)
    {
        // How to get the tapped cell index here??
    
        var index = MenuCellTexts.IndexOf(item);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-07
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多