Вам необходимо создать класс, который наследуется от UITableViewSource
. Вам необходимо реализовать по крайней мере два метода в этом новом: GetCell
и RowsInSection
. Вы можете использовать пользовательский UITableViewCell
, чтобы создать точный дизайн ячейки, или вы можете использовать свойство Accessory
, чтобы изменить принадлежность ячейки, когда ячейка была выбрана. Вы должны иметь что-то похожее на это:
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();
}
}
И создать свой экземпляр UITableView
(например, в ViewDidLoad
):
this.tableView.Source = new SimpleTableViewSource();
this.tableView.ReloadData();
Это то, что вам нужно сделать самостоятельно. Если была выбрана строка, вам необходимо обновить свою модель и отобразить галочку в пользовательском интерфейсе с помощью пользовательского UITableViewCell. – Krumelur
Хорошо, спасибо! Я думал, что может быть какое-то поведение по умолчанию UITableView, поскольку я видел это поведение в почтовом приложении. Ну что ж! – binncheol
Обязательно попробуйте MonoTouch.Dialog (https://github.com/migueldeicaza/MonoTouch.Dialog), это упростит вашу жизнь. – Krumelur