Пример #1
0
 public ComparableTableView(RectangleF frame, UITableViewStyle style, ComparableModel comparable, UIViewController viewController) : base(frame, style)
 {
     _tableViewSource             = new ComparableTableViewSource(this, comparable, viewController);
     _tableViewSource.OnEditUnit += (sender, args) =>
     {
         OnEditUnit.Fire(this, args);
         ResignTextFieldAsFirstResponder();
     };
     _tableViewSource.OnKeyboardDone += (sender, args) =>
     {
         OnKeyboardDone.Fire(this, EventArgs.Empty);
     };
     Source          = _tableViewSource;
     AllowsSelection = false;
 }
Пример #2
0
        public ComparisonTableView(RectangleF frame, UITableViewStyle style) : base(frame, style)
        {
            _source             = new ComparisonTableViewSource(this);
            _source.OnEditUnit += (sender, args) =>
            {
                OnEditUnit.Fire(this, args);
                ResignTextFieldAsFirstResponder();
            };
            _source.OnKeyboardDone += (sender, args) =>
            {
                OnKeyboardDone.Fire(this, EventArgs.Empty);
            };
            _source.OnNameChanged += (sender, args) =>
            {
                OnNameChanged.Fire(this, EventArgs.Empty);
            };
            Source          = _source;
            ScrollEnabled   = false;
            AllowsSelection = false;

            var footerView = new UIView(new RectangleF(0, 0, Frame.Width, 34));

            footerView.Center = new PointF(Frame.Width / 2, 17);
            var footerLabel = new UILabel(new RectangleF(0, 0, footerView.Frame.Width - 100, 34));

            footerLabel.Center          = new PointF(footerView.Frame.Width / 2, 17);
            footerLabel.TextAlignment   = UITextAlignment.Center;
            footerLabel.Text            = "Comparisons will be performed using this base unit";
            footerLabel.Lines           = 2;
            footerLabel.Font            = UIFont.FromName("Helvetica", 14);
            footerLabel.BackgroundColor = UIColor.Clear;
            footerLabel.TextColor       = UIColor.DarkGray;
            footerLabel.ShadowColor     = UIColor.White;
            footerLabel.ShadowOffset    = new SizeF(0, 1);
            footerView.AddSubview(footerLabel);

            TableFooterView = footerView;
        }
Пример #3
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            EventedTableViewCell cell;

            switch (indexPath.Row)
            {
            case (0):
                cell = new EventedTableViewCell();
                AddLabel(cell, "Name");
                ComparisonNameText = AddTextField(cell, "comparison name (i.e. Apples)", indexPath, () =>
                {
                    OnKeyboardDone.Fire(this, EventArgs.Empty);
                    return(null);
                });
                ComparisonNameText.EditingChanged += (sender, args) =>
                {
                    OnNameChanged.Fire(this, EventArgs.Empty);
                };
                ComparisonNameText.ReturnKeyType          = UIReturnKeyType.Done;
                ComparisonNameText.AutocapitalizationType = UITextAutocapitalizationType.Words;
                break;

            case (1):
                cell = new EventedTableViewCell();
                AddLabel(cell, "Compare by");
                // add segmented control
                UnitTypeSegmented = new EventedSegmentedControl(new RectangleF(120, 7, 180, 30));
                UnitTypeSegmented.ControlStyle = UISegmentedControlStyle.Bar;
                UnitTypeSegmented.InsertSegment("Weight", 0, false);
                UnitTypeSegmented.InsertSegment("Volume", 1, false);
                UnitTypeSegmented.InsertSegment("Each", 2, false);
                UnitTypeSegmented.SelectedSegment = 0;

                UnitTypeSegmented.ValueChanged += (sender, args) =>
                {
                    _tableView.FireOnUnitTypeChanged();
                };

                UnitTypeSegmented.OnTouchesEnded += (sender, args) =>
                {
                    if (ComparisonNameText.IsFirstResponder)
                    {
                        ComparisonNameText.ResignFirstResponder();
                    }
                };

                cell.AddSubview(UnitTypeSegmented);
                break;

            case (2):
                cell = new EventedTableViewCell();
                AddLabel(cell, "Base unit");
                UnitLabel           = new UILabel(new RectangleF(0, 0, cell.Frame.Width - 115, 20));
                UnitLabel.Center    = new PointF(200, (cell.Frame.Height / 2) + 1);
                UnitLabel.Text      = "ounces";
                UnitLabel.Font      = UIFont.FromName("Helvetica", 14);
                UnitLabel.TextColor = UIColor.DarkTextColor;
                cell.AddSubview(UnitLabel);
                cell.OnTouchesEnded += (sender, args) =>
                {
                    ActiveIndexPath = indexPath;
                    OnEditUnit.Fire(this, EventArgs.Empty);
                };

                break;

            default:
                throw new ArgumentException("Invalid row index: " + indexPath.Row);
            }
            return(cell);
        }
Пример #4
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            switch (indexPath.Row)
            {
            case (0):
                if (_productCell == null)
                {
                    _productCell = new EventedTableViewCell();
                    AddLabel(_productCell, "Product");
                    ProductText      = AddTextField(_productCell, "or brand name", indexPath, () => { return(StoreText); });
                    ProductText.Text = _comparable == null ? null : _comparable.Product;
                    ProductText.AutocapitalizationType = UITextAutocapitalizationType.Words;
                    ProductText.EditingChanged        += (sender, args) =>
                    {
                        _tableView.FireOnProductNameChanged();
                    };
                }
                return(_productCell);

            case (1):
                if (_storeCell == null)
                {
                    _storeCell           = new EventedTableViewCell();
                    _storeCell.Accessory = UITableViewCellAccessory.DetailDisclosureButton;
                    AddLabel(_storeCell, "Store");
                    StoreText      = AddTextField(_storeCell, "store name (optional)", indexPath, () => { return(PriceText); });
                    StoreText.Text = _comparable == null ? null : _comparable.Store;
                    StoreText.AutocapitalizationType = UITextAutocapitalizationType.Words;
                    StoreText.Frame = new RectangleF(StoreText.Frame.X, StoreText.Frame.Y, StoreText.Frame.Width - 30, StoreText.Frame.Height);
                }
                return(_storeCell);

            case (2):
                if (_priceCell == null)
                {
                    _priceCell = new EventedTableViewCell();
                    AddLabel(_priceCell, "Price");
                    PriceText = AddTextField(_priceCell, "0.00", indexPath, () => { return(QuantityText); });
                    PriceText.KeyboardType = UIKeyboardType.DecimalPad;
                    var label = new UILabel(new RectangleF(0, 10, 9, 18));
                    label.TextColor        = UIColor.LightGray;
                    label.Font             = UIFont.FromName("Helvetica", 14);
                    label.Text             = "$";
                    PriceText.LeftView     = label;
                    PriceText.LeftViewMode = UITextFieldViewMode.Always;
                    PriceText.Text         = _comparable == null ? null : _comparable.Price.ToString();
                }
                return(_priceCell);

            case (3):
                if (_quantityCell == null)
                {
                    _quantityCell = new EventedTableViewCell();
                    AddLabel(_quantityCell, "Quantity");
                    QuantityText = AddTextField(_quantityCell, "quantity", indexPath, () =>
                    {
                        OnKeyboardDone.Fire(this, EventArgs.Empty);
                        return(null);
                    });
                    QuantityText.KeyboardType  = UIKeyboardType.DecimalPad;
                    QuantityText.ReturnKeyType = UIReturnKeyType.Done;
                    QuantityText.Text          = _comparable == null ? null : _comparable.Quantity.ToString();
                }
                return(_quantityCell);

            case (4):
                if (_unitCell == null)
                {
                    _unitCell = new EventedTableViewCell();
                    AddLabel(_unitCell, "Unit");
                    UnitLabel           = new UILabel(new RectangleF(0, 0, _unitCell.Frame.Width - 115, 20));
                    UnitLabel.Center    = new PointF(200, (_unitCell.Frame.Height / 2));
                    UnitLabel.Font      = UIFont.FromName("Helvetica", 14);
                    UnitLabel.TextColor = UIColor.DarkTextColor;
                    _unitCell.AddSubview(UnitLabel);
                    _unitCell.OnTouchesEnded += (sender, args) =>
                    {
                        ActiveIndexPath = indexPath;
                        OnEditUnit.Fire(this, EventArgs.Empty);
                    };
                }
                return(_unitCell);

            default:
                throw new ArgumentException("Invalid row index: " + indexPath.Row);
            }
        }