在UITableView单元格中选择UIPIcker索引

时间:2019-07-10 13:40:04

标签: c# ios swift xamarin xamarin.ios

我在一个单元格中创建了一个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

1 个答案:

答案 0 :(得分:0)

我将AddSelection方法更改为此

public void AddSelection (MobilePreOrderMenuModel selectedProduct)
{
    TypePicker.Select (SelectedOrDefault (selectedProduct.Menu [0].Types [0].Products),0, true);
}

我将参数固定在Select上,现在可以使用了。

enter image description here

Select的声明为

void UIPickerView.Select(nint row, nint component, bool animated);