Example #1
0
 public HomeTableViewSource(HomeTableView tableView)
 {
     _tableView = tableView;
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title = "Cheapster";

            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, (sender, args) =>
            {
                OnAddComparison.Fire(this, EventArgs.Empty);
            });

            _tableView = new HomeTableView(new RectangleF(0, 0, View.Frame.Width, View.Frame.Height - 88), UITableViewStyle.Plain);

            _tableView.Opaque = false;
            _tableView.Alpha  = 0;

            _tableView.OnComparisonSelected += (sender, args) =>
            {
                NavigationItem.BackBarButtonItem = new UIBarButtonItem("Home", UIBarButtonItemStyle.Bordered, null);
                SelectedComparison = _tableView.GetSelectedComparison();
                OnComparisonSelected.Fire(this, EventArgs.Empty);
            };
            _tableView.OnComparisonDeleted += (sender, args) =>
            {
                if (_tableView.Comparisons.Count > 0)
                {
                    return;
                }

                _trashButton.Enabled = false;

                if (_tableView.Editing)
                {
                    NavigationItem.RightBarButtonItem.Enabled = true;
                    _tableView.SetEditing(false, true);
                }
            };
            View.AddSubview(_tableView);

            _toolbar           = new UIToolbar(new RectangleF(0, View.Frame.Height - 88, View.Frame.Width, 44));
            _toolbar.TintColor = UIColor.DarkGray;
            var toolbarItems = new List <UIBarButtonItem>();

            _trashButton = new UIBarButtonItem(UIBarButtonSystemItem.Trash, (sender, args) =>
            {
                NavigationItem.RightBarButtonItem.Enabled = _tableView.Editing;
                _tableView.SetEditing(!_tableView.Editing, true);
            });

            var infoButton = UIButton.FromType(UIButtonType.InfoLight);

            infoButton.TouchUpInside += (sender, args) =>
            {
                OnInfoButton.Fire(this, EventArgs.Empty);
            };

            toolbarItems.Add(new UIBarButtonItem(infoButton));
            toolbarItems.Add(new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace));
            toolbarItems.Add(_trashButton);
            _toolbar.SetItems(toolbarItems.ToArray(), false);
            View.AddSubview(_toolbar);

            if (_tableView.Comparisons.Count == 0)
            {
                _trashButton.Enabled = false;
            }
        }