uitableview - 将 MvxBindableTableViewCell 的附件绑定(bind)到 bool 值

标签 uitableview xamarin.ios mvvmcross

我被困在如何将 MvxBindableTableViewCell 的附件绑定(bind)到 bool 值上。

我将表的 ItemsSource 绑定(bind)到我的 ViewModel 中的列表,显示了一个不错的可点击项目列表。

但是我希望单元格的附件 (UITableViewCellAccessory.Checkmark) 仅在标记此对象时显示。标记是指模型中的 bool 值设置为真。

有谁知道如何绑定(bind)手机配件?

编辑: 我可以根据模型的 bool 值显示附件,但它没有绑定(bind)。

protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath     indexPath, object item)
    {
        UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
        if (cell == null)
            cell = new PlotsTableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier);

        Plot p = (Plot)item;
        if (p.Done)
            cell.Accessory = UITableViewCellAccessory.Checkmark;
        return cell;
    }

最佳答案

我认为您可以在 PlotsTableViewCell 中执行此操作。

如果您声明了一个自定义单元格,那么您可以在运行时在该单元格内进行绑定(bind)。

您可以在以下位置查看示例:https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Cells/SessionCell2.cs在 session 显示中使用:

Cell

您可以看到单元格提供公共(public)属性,例如:

public string RoomText
    {
    get { return Label2.Text; }
    set { if (Label2 != null) Label2.Text = value; }
    }

然后提供绑定(bind)文本,如:

    'RoomText':{'Path':'Item.Session','Converter':'SessionSmallDetails','ConverterParameter':'SmallDetailsFormat'},

要将附件绑定(bind)到 Bool,您应该能够执行以下操作:

public bool IsDone
    {
    get { return Accessory == UITableViewCellAccessory.Checkmark; }
    set 
    {
        if (value) 
        {
            Accessory = UITableViewCellAccessory.Checkmark; 
        }
        else 
        {
            Accessory = UITableViewCellAccessory.None; 
        }
    }
    }

带文字:

    'IsDone':{'Path':'Done'},

作为一种高级技术,您还可以在自定义绘制的按钮内使用自定义图像,而不是在您的单元格中使用附件。要了解如何执行此操作,请查看 IsFavorite 属性如何在该 session 示例中绑定(bind) - 请参阅 https://github.com/slodge/MvvmCross/tree/vnext/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Bindings 中的两种自定义绑定(bind)方式

关于uitableview - 将 MvxBindableTableViewCell 的附件绑定(bind)到 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974166/

相关文章:

ios - 单击 UITableViewCell 中的 UIbuttion 如何更改 uilabel 文本

c# - 您可以并排放置两个编辑字段吗?

ios - 错误 MT1006 容器创建失败

ios - dequeueReusableCellWithIdentifier 中的断言失败 :forIndexPath:

ios - 为表格 View 单元格添加自定义字体

ios - 当圆形蒙版应用于 ImageView 时,UIImageView 中的图像不显示在 UITableView 中,除非滚动

c# - 在 Binding 项目中实现 MKAnnotation 协议(protocol)

xamarin.ios - MvvmCross:MonoTouch 中的绑定(bind)列表

http - Xamarin MvvmCross HTTP请求: How does this work?

c# - 在一个服务的方法中运行多个任务