Я клянусь, что я искал всю базу данных Google для возможного решения, но я до сих пор застрял в этом вопросе :)Получить значения из UITextFields внутри пользовательских UITableViewCell
В принципе, у меня есть 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 (который, как я понимаю, может быть невозможен) ,
Итак, если кто-то может пролить свет на мой нынешний подход, независимо от того, осуществимо это или нет, или я должен смотреть на повторное выполнение всего этого все вместе.
У вас есть доступ к базе данных Google? Я завидую вам;) –
Мы все делаем Mr @Kettler :) – Marko