Клянусь, я искал всю базу данных Google для возможного решения, но я все еще застрял в этой проблеме:)
В принципе, у меня есть 12 строк в таблице базы данных, для которой я генерирую пользовательскийUITableViewCell с 4 UITextFields внутри.Столбцы таблицы выглядят так: (SQLITE)
EntryFieldID NUMBER
Description TEXT
FieldType TEXT
Теперь я хочу, чтобы каждый тег UITableViewCell
был выше EntryFieldID
, поэтому я могу легко вернуться к нему позже для хранения.в другой таблице.Эта таблица выглядит следующим образом.
OrderID NUMBER
EntryFieldID NUMBER
Value1 TEXT
Value2 TEXT
Value3 TEXT
Value4 TEXT
4 поля значения * - это 4 UITextFields
, которые находятся внутри каждого UIViewCell
.
Надеемся, что это имеет смысл до сих пор:)
Теперь внутри моего TableViewSource У меня есть этот код:
protected List<InfoCaptureTableViewGroup> _tableItems;
protected string _customCellIdentifier = "InfoCaptureField";
protected Dictionary<int, InfoCaptureTableViewCell> _cellControllers = new Dictionary<int, InfoCaptureTableViewCell>();
public InfoCaptureTableSource (List<InfoCaptureTableViewGroup> items)
{
this._tableItems = items;
}
/// <summary>
/// Called by the TableView to determine how many sections(groups) there are.
/// </summary>
public override int NumberOfSections (UITableView tableView)
{
return this._tableItems.Count;
}
/// <summary>
/// Called by the TableView to determine how many cells to create for that particular section.
/// </summary>
public override int RowsInSection (UITableView tableview, int section)
{
return this._tableItems[section].Items.Count;
}
/// <summary>
/// Called by the TableView to retrieve the header text for the particular section(group)
/// </summary>
public override string TitleForHeader (UITableView tableView, int section)
{
return this._tableItems[section].Name;
}
/// <summary>
/// Called by the TableView to retrieve the footer text for the particular section(group)
/// </summary>
public override string TitleForFooter (UITableView tableView, int section)
{
return this._tableItems[section].Footer;
}
/// <summary>
/// Called by the TableView to retreive the height of the row for the particular section and row
/// </summary>
public override float GetHeightForRow (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
return 44f;
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
// is there a way to NOT reuse cells? There's only ever going to be 12 of them
UITableViewCell cell = tableView.DequeueReusableCell (this._customCellIdentifier);
InfoCaptureTableViewCell customCellController = null;
InfoCaptureField item = this._tableItems[indexPath.Section].Items[indexPath.Row];
//---- if there are no cells to reuse, create a new one
if (cell == null)
{
customCellController = new InfoCaptureTableViewCell();
// retrieve the cell from our custom cell controller
cell = customCellController.Cell;
// disable selection
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
// This is where I'd like to use the EntryFieldID
cell.Tag = Environment.TickCount;
// store our controller with the unique ID we gave our cell
this._cellControllers.Add (cell.Tag, customCellController);
}
else
{
// retrieve our controller via it's unique ID
customCellController = this._cellControllers[cell.Tag];
}
//---- return the custom cell
return cell;
}
Код выше на самом деле не имеет большого смысла для меня, этобыл скопирован с примера MonoTouch.Я понимаю, что ячейки используются повторно, но на самом деле я бы хотел избежать этого, чтобы я мог использовать EntryFieldID для свойства Tag пользовательской ячейки, а также, чтобы я мог перебирать все строки UITableView (что, как я теперь понимаю, может оказаться невозможным).
Итак, если кто-то может пролить некоторый свет на мой текущий подход, осуществим ли он или нет, или мне следует подумать о повторной реализации всего этого вместе.