unable to get my Custom View cell to appear on Navigation View Controller

8 replies. Last post: June 19, 2014 12:28 AM by Yudi
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback

I took the Master-Detail Wizard and I want to display custom view cells on that page. I need to expand the row to 152 pixels and I overrode the GetRowHeight on both the UITableViewController and it's delegate and it never hits that method to get the row height. What am I doing wrong?


[Register("MainViewController")]
	[ImportBinding(typeof(NavigationBindingProvider))]
	public class MainViewController : UITableViewController<NavigationViewModel>
    {
        #region Properties

        public override TableViewInteraction InteractionMode
        {
            get { return TableViewInteraction.Navigation; }
        }

		public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
		{
			return 152;
		}

		public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
		{
			return base.GetCell (tableView, indexPath);
		}

        public override bool ShowGroupHeader
        {
			get { return false; }
        }

        public override UITableViewStyle TableViewStyle
        {
			get { return UITableViewStyle.Grouped; }
        }

		public override TableViewCellStyle CellStyle
		{
			get
			{
				return TableViewCellStyle.Custom;
			}
		}

		public override UIViewTemplate CellTemplate
		{
			get
			{
				return new UIViewTemplate(BridgeTableViewCell.Nib);
			}
		}

		public override string CellIdentifier
		{
			get
			{
				return "BridgeTableViewCell";
			}
		}
        #endregion

        #region Methods

        protected override void InitializeView()
        {
            base.InitializeView();

            var label = new UILabel();
            label.Text = "Powered by Crosslight®";
            label.BackgroundColor = UIColor.Clear;
            label.TextColor = UIColor.DarkGray;
            label.ShadowColor = UIColor.White.ColorWithAlpha(0.8f);
            label.ShadowOffset = new SizeF(1, 1);
            label.Font = UIFont.SystemFontOfSize(14f);
            //label.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
            label.SizeToFit();
            label.Frame = new RectangleF(label.Frame.Left, label.Frame.Top, label.Frame.Width, label.Frame.Height + 8);
            label.Center = new PointF(this.View.Bounds.Width / 2, label.Bounds.Height / 2);

            // set TableView footer
            this.TableView.TableFooterView = label;

            // set navigation title
            this.NavigationItem.Title = "Crosslight App";

			this.Appearance.BackgroundColor = UIColor.Clear;
			this.Appearance.BackgroundImage = "Bridge5.png";
			this.TableView.Delegate = new MainTableDelegate ();
        }

		private class MainTableDelegate : UITableViewDelegate {
			public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
			{
				return 152;
			}
		}
        #endregion
    }
}

Navigation View Model

public class NavigationViewModel : SampleListViewModelBase<BridgeNavigationItem>
    {
		private CameraRepository _repository;

        #region Properties

        public string AboutText
        {
            get { return _aboutText; }
            set
            {
                if (_aboutText != value)
                {
                    _aboutText = value;
                    OnPropertyChanged("AboutText");
                }
            }
        }


        private string _aboutText { get; set; }

        #endregion

        #region Constructors

        public NavigationViewModel()
        {
			List<BridgeNavigationItem> items = new List<BridgeNavigationItem>();

			_repository = new CameraRepository ();

			foreach (string item in _repository.GetAll()) {
				items.Add(new BridgeNavigationItem(item, "Piedras N...", typeof(CrossingOwlViewModel)));
			}
			//items.AddRange (_repository.GetAll ());
			//items.Add (new NavigationItem ("Crossing Owls", "Cameras", typeof(CrossingOwlViewModel)));
			//items.Add(new NavigationItem("Simple Page", "About", typeof(SimpleViewModel)));
			//items.Add(new NavigationItem("About This App", "About", typeof(AboutNavigationViewModel)));

			this.SourceItems = items;
            this.RefreshGroupItems();
        }

        #endregion

        #region Methods


        public override void RefreshGroupItems()
        {
            if (this.Items != null)
                this.GroupItems = this.Items.GroupBy(o => o.Group).Select(o => new GroupItem<NavigationItem>(o)).ToList();
        }


        #endregion
    }


BridgeNavigationItem

		public BridgeNavigationItem (string title, NavigationTarget target) : base(title, target)
		{
		}

		public BridgeNavigationItem(string title, string group, NavigationTarget target) : base(title, group, target) {
		}

		public BridgeNavigationItem(string title, string group, Type target) : base(title, group, target) {
		}

		public string BridgeName {
			get {
				return "Hello Bridge";
			}
		}
	}

NavigationBindingProvider

    public class NavigationBindingProvider : BindingProvider
    {
        #region Constructors

        public NavigationBindingProvider()
        {
            ItemBindingDescription itemBinding = new ItemBindingDescription()
            {
                DisplayMemberPath = "Title",
                NavigateMemberPath = "Target"
            };

            this.AddBinding("TableView", BindableProperties.ItemsSourceProperty, "Items");
            this.AddBinding("TableView", BindableProperties.ItemTemplateBindingProperty, itemBinding, true);
            this.AddBinding("TableView", BindableProperties.SelectedItemProperty, "SelectedItem", BindingMode.TwoWay);
        }

        #endregion
    }



All times are GMT -5. The time now is 2:57 PM.
Previous Next