| trunk/Plateau/Source/Plateau/PTPicker.pas |
| 11 | 11 | PTPicker = public class |
| 12 | 12 | protected |
| 13 | 13 | picker: UIPickerView; |
| 14 | actionSheet: UIActionSheet; |
| 14 | 15 | fDataSource: PTPickerModel; |
| 15 | 16 | ownerView: UIView; |
| 16 | 17 | |
| ... | ... | |
| 19 | 20 | public |
| 20 | 21 | protected |
| 21 | 22 | method ShowActionSheetPicker(); |
| 23 | method HidePicker; |
| 22 | 24 | public |
| 23 | 25 | constructor (view: UIView); |
| 24 | 26 | property DataSource: PTPickerModel read fDataSource write set_DataSource; |
| 25 | 27 | property Title: String; |
| 28 | property CloseOnSelect : boolean; |
| 26 | 29 | |
| 27 | 30 | event ItemSelected: EventHandler<PTPickerItemSelectedEventArgs>; |
| 28 | 31 | |
| ... | ... | |
| 35 | 38 | begin |
| 36 | 39 | if self.ItemSelected <> nil then |
| 37 | 40 | begin |
| 38 | | self.ItemSelected(sender, e) |
| 41 | self.ItemSelected(sender, e); |
| 42 | if self.CloseOnSelect then |
| 43 | HidePicker; |
| 39 | 44 | end |
| 40 | 45 | end; |
| 41 | 46 | |
| ... | ... | |
| 47 | 52 | method PTPicker.ShowActionSheetPicker(); |
| 48 | 53 | begin |
| 49 | 54 | //---- declare vars |
| 50 | | var actionSheet: UIActionSheet; |
| 55 | |
| 51 | 56 | var btnDone: UIButton := UIButton.FromType(UIButtonType.RoundedRect); |
| 52 | 57 | var lblActionSheetTitle: UILabel := new UILabel(); |
| 53 | 58 | var titleFont: UIFont := UIFont.BoldSystemFontOfSize(18); |
| ... | ... | |
| 85 | 90 | |
| 86 | 91 | //---- add the delegate to dismiss the action sheet |
| 87 | 92 | btnDone.TouchDown += method (sender: Object; e: EventArgs) begin |
| 88 | | //this._dataSource.Selected (this._lstPicker, 0, 0); |
| 89 | | actionSheet.DismissWithClickedButtonIndex(0, true) |
| 93 | HidePicker; |
| 90 | 94 | end; |
| 91 | 95 | |
| 92 | 96 | //---- show the action sheet and add the controls to it |
| 93 | 97 | actionSheet.ShowInView(self.ownerView); |
| 94 | 98 | actionSheet.AddSubview(self.picker); |
| 95 | 99 | actionSheet.AddSubview(lblActionSheetTitle); |
| 96 | | actionSheet.AddSubview(btnDone); |
| 100 | if not self.CloseOnSelect then |
| 101 | actionSheet.AddSubview(btnDone); |
| 97 | 102 | |
| 98 | 103 | //---- if something is already selected |
| 99 | 104 | if self.dataSource.SelectedItem <> '' then |
| 100 | 105 | begin |
| 101 | 106 | Console.WriteLine('this._dataSource.SelectedItem = ' + self.dataSource.SelectedItem); |
| 102 | | Console.WriteLine('this._dataSource.SelectedComponentIndex, this._dataSource.SelectedRowIndex,' + self.dataSource.SelectedComponentIndex.ToString() + ',' + self.dataSource.SelectedRowIndex.ToString()) |
| 103 | | //this._lstPicker.Select (this._dataSource.SelectedComponentIndex, this._dataSource.SelectedRowIndex, true); |
| 107 | Console.WriteLine('this._dataSource.SelectedComponentIndex, this._dataSource.SelectedRowIndex,' + self.dataSource.SelectedComponentIndex.ToString() + ',' + self.dataSource.SelectedRowIndex.ToString()); |
| 108 | self.picker.Select(self.dataSource.SelectedRowIndex, self.dataSource.SelectedComponentIndex, true); |
| 104 | 109 | end; |
| 105 | 110 | |
| 106 | 111 | //---- resize the action sheet to fit our other stuff |
| ... | ... | |
| 117 | 122 | btnDone.Frame := new RectangleF(actionSheetWidth - btnDoneWidth - 10, 7, btnDoneWidth, btnDoneHeight) |
| 118 | 123 | end; |
| 119 | 124 | |
| 125 | method PTPicker.HidePicker; |
| 126 | begin |
| 127 | //this._dataSource.Selected (this._lstPicker, 0, 0); |
| 128 | actionSheet.DismissWithClickedButtonIndex(0, true) |
| 129 | end; |
| 130 | |
| 120 | 131 | constructor PTPicker(view: UIView); |
| 121 | 132 | begin |
| 122 | 133 | self.ownerView := view; |
| 123 | 134 | |