C# 单触式UITableView Multiselect

C# 单触式UITableView Multiselect,c#,ios,uitableview,xamarin.ios,C#,Ios,Uitableview,Xamarin.ios,我很难理解如何使用Monotouch实现以下风格的多点触控UITableView: 我有UITableView使用“幻灯片删除”功能。我还添加了以下内容: logsTable.AllowsMultipleSelection = true; logsTable.AllowsMultipleSelectionDuringEditing = true; 这允许我选择行,但是圆圈和记号不会出现。这是默认的iOS功能还是我必须单独实现它?您需要创建一个继承自UITableViewSource的类。您需

我很难理解如何使用Monotouch实现以下风格的多点触控
UITableView

我有
UITableView
使用“幻灯片删除”功能。我还添加了以下内容:

logsTable.AllowsMultipleSelection = true;
logsTable.AllowsMultipleSelectionDuringEditing = true;

这允许我选择行,但是圆圈和记号不会出现。这是默认的iOS功能还是我必须单独实现它?

您需要创建一个继承自
UITableViewSource
的类。您需要在这个新创建的应用程序中至少实现两个方法:
GetCell
rowsinssection
。您可以使用自定义的
UITableViewCell
创建单元格的精确设计,也可以使用
附件
属性在选择单元格时修改单元格附件。你应该有类似的东西:

private class SimpleTableViewSource : UITableViewSource
{
   // Some data. Item1 will serve as the Text and Item2 will be a value indicating whether the cell is selected or not
   private List<Tuple<string, bool>> Data { get; set; }

   public SimpleTableViewSource()
   {
       this.Data = new List<Tuple<string, bool>>() {
           Tuple.Create("Item 1", false),
           Tuple.Create("Item 2", false),
           Tuple.Create("Item 3", false),
           Tuple.Create("Item 4", false),
           Tuple.Create("Item 5", false),
           Tuple.Create("Item 6", false),
           Tuple.Create("Item 7", false)
       };
   }

   public override int RowsInSection(UITableView tableview, int section)
   {
       return this.Data.Count;
   }

   public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
   {
       UITableViewCell cell = tableView.DequeueReusableCell("cell") ?? new UITableViewCell();

       cell.TextLabel.Text = this.Data[indexPath.Row].Item1;

       // if the row is selected show checkmark
       if (this.Data[indexPath.Row].Item2)
       {
           cell.Accessory = UITableViewCellAccessory.Checkmark;
       }
       else
       {
           cell.Accessory = UITableViewCellAccessory.None;
       }

       return cell;
   }

   public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
   {
       UITableViewCell cell = tableView.DequeueReusableCell("cell") ?? new UITableViewCell();
       cell.Selected = !this.Data[indexPath.Row].Item2;
       this.Data[indexPath.Row] = Tuple.Create(this.Data[indexPath.Row].Item1, !this.Data[indexPath.Row].Item2);
       tableView.ReloadData();
   }    
}
您只需添加:

logsTable.SetEditing(true,true)

或隐藏


logsTable.SetEditing(假、真)

这是你必须自己做的事情。如果选择了一行,则需要使用自定义UITableViewCell更新模型并在UI中反映复选标记。好的,谢谢!我认为可能存在一些默认的UITableView行为,正如我在邮件应用程序中看到的那样。哦,好吧!一定要试试MonoTouch.Dialog(),它会让你的生活更轻松。
this.tableView.Source = new SimpleTableViewSource();
this.tableView.ReloadData();