Beispiel #1
0
        public static Task <SampleItem[]> GetSelectedItemsAsync(UIViewController viewController, SampleItem[] items,
                                                                SampleItem[] itemsSelected, string title,
                                                                bool allowMultipleSelection, bool allowFiltering)
        {
            //     var storyboard = UIStoryboard.FromName("Main", null);
            //     var vc = (SelectionViewController)storyboard.InstantiateViewController(nameof(SelectionViewController));

            var vc = new SelectionViewController2();

            vc.Title = title;
            vc._allowMultipleSelection = allowMultipleSelection;
            vc._allowFiltering         = allowFiltering;
            vc._tcs           = new TaskCompletionSource <SampleItem[]>();
            vc._items         = items;
            vc._itemsSelected = itemsSelected;

            var nav = new UINavigationController(vc);

            if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                nav.PresentationController.Delegate = new UIAdaptivePresentationController(vc._tcs);
            }

            viewController.PresentViewController(nav, true, null);

            return(vc._tcs.Task);
        }
Beispiel #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.


            Button.TouchUpInside += async(sender, args) =>
            {
                var items = new[]
                {
                    new SampleItem("Roxanne Bailey"),
                    new SampleItem("Jack Clayton"),
                    new SampleItem("Ron Lynch"),
                    new SampleItem("Pat Garrett"),
                    new SampleItem("Irma Norton"),
                    new SampleItem("Kathy Dennis")
                };

                var selectedItems = items.Take(Switch.On ? 2 : 1).ToArray();

                var result = await SelectionViewController2.GetSelectedItemsAsync(this, items, selectedItems,
                                                                                  "Test", Switch.On, true);

                if (result.Length == 1 && result[0] != selectedItems[0])
                {
                    //add the item back
                }

                Debug.WriteLine("Selected items:");
                foreach (var item in result)
                {
                    Debug.WriteLine($"\t{item.Name}");
                }
            };
        }