我在一个单元格中创建了一个UITableView
的{{1}}。我想将值添加到选择器上,然后转到用户选择的项目。
UIPickerView
方法将值添加到选择器,而UpdateCell
方法选择选择器项目索引。
我超出范围例外,因为AddSelection
试图选择索引,但是AddSelection
尚未完成。仅适用于0索引。
在UpdateCell
类中……
PreOrderMenuTableSource
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
// Product Title
if (indexPath.Section == 0) {
cellIdentifier = new NSString ("preOrderMenuInfoCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as PreOrderMenuDescriptionCell;
cell.UpdateCell (SelectedMenu);
return cell;
}
// Product Description
if (indexPath.Section == 1) {
cellIdentifier = new NSString ("preOrderMenuDescCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as PreOrderMenuTitleCell;
cell.UpdateCell (SelectedMenu);
return cell;
}
//Product Type Cell
if (indexPath.Section == 2) {
cellIdentifier = new NSString ("preOrderTypeCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as PreOrderMenuTypeCell;
cell.UpdateCell (SelectedMenu);
cell.AddSelection (SelectedMenu);
return cell;
}
// Comments
if (indexPath.Section == 3) {
cellIdentifier = new NSString ("preOrderMenuCommentCell");
var cell = tableView.DequeueReusableCell (cellIdentifier) as PreOrderMenuCommentCell;
cell.Setup (tableView, indexPath);
return cell;
}
else {
return null;
}
}
是以下...
PreOrderMenuTypeCell
partial class PreOrderMenuTypeCell : UITableViewCell
{
public PreOrderMenuTypeCell (IntPtr handle) : base (handle)
{
}
public void UpdateCell (MobilePreOrderMenuModel selectedProduct)
{
TypeTitle.Text = selectedProduct.Menu [0].Types[0].Name;
var typePickerModel = new PreOrderTypePickerModel (selectedProduct.Menu [0].Types [0].Products);
TypePicker.Model = typePickerModel;
}
public void AddSelection (MobilePreOrderMenuModel selectedProduct)
{
TypePicker.Select (0, SelectedOrDefault (selectedProduct.Menu [0].Types [0].Products), true);
}
private int SelectedOrDefault (List<MobilePreOrderProductDetails> products)
{
var selected = products.Where (x => x.IsSelected).FirstOrDefault ();
if (selected != null) {
return selected.Sequence.Value-1;
}
else {
var defaultSelected = products.OrderBy (x => x.Sequence).FirstOrDefault ();
defaultSelected.IsSelected = true;
return 0;
}
}
}
是以下...
PreOrderTypePickerModel
答案 0 :(得分:0)