public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
            {
                try {
                    var section = controller.Sections [indexPath.Section];
                    var item    = section.Items [indexPath.Row];

                    var itemDisplay = section.GetItemDisplay(item);
                    var id          = item.GetType().Name + itemDisplay;

                    var cell = tableView.DequeueReusableCell(id) as PFormCell;

                    if (cell == null)
                    {
                        cell = new PFormCell(itemDisplay, id);
                    }

                    try {
                        cell.Format(section, item);
                    } catch (Exception ex) {
                        Debug.WriteLine(ex);
                    }

                    return(cell);
                } catch (Exception ex) {
                    Log.Error(ex);
                    return(new UITableViewCell());
                }
            }
			public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
			{
				try {
					
					var section = controller.Sections [indexPath.Section];
					var item = section.Items [indexPath.Row];

					var itemDisplay = section.GetItemDisplay (item);
					var id = item.GetType ().Name + itemDisplay;

					var cell = tableView.DequeueReusableCell (id) as PFormCell;

					if (cell == null) {
						cell = new PFormCell (itemDisplay, id);
					}

					try {
						FormatCell (cell, section, item);
					} catch (Exception ex) {
						Debug.WriteLine (ex);
					}

					return cell;
				} catch (Exception ex) {
					Log.Error (ex);
					return new UITableViewCell ();
				}

			}
			public void FormatCell (PFormCell cell, PFormSection section, object item)
			{
				var theme = Theme.Current;
				theme.Apply (cell);

				var itemTitle = section.GetItemTitle (item);
				cell.TextLabel.Text = itemTitle;
				cell.TextLabel.AccessibilityLabel = itemTitle;
				cell.TextLabel.BackgroundColor = UIColor.Clear;

				var display = section.GetItemDisplay (item);
				if (display != PFormItemDisplay.Title) {
					cell.DetailTextLabel.Text = section.GetItemDetails (item) ?? "";
					if (display == PFormItemDisplay.TitleAndValue) {
						cell.DetailTextLabel.TextColor = UIApplication.SharedApplication.KeyWindow.TintColor;
					}
				}

				var imageUrl = section.GetItemImage (item);
				if (string.IsNullOrEmpty (imageUrl)) {
					cell.ImageView.Image = null;
				} else {
					UIImage image;
					if (!imageCache.TryGetValue (imageUrl, out image)) {
						image = UIImage.FromBundle (imageUrl);
						imageCache.Add (imageUrl, image);
					}
					cell.ImageView.Image = image;
				}

				if (section.GetItemChecked (item)) {
					cell.Accessory = UITableViewCellAccessory.Checkmark;

					theme.ApplyChecked (cell);


				} else {
					cell.Accessory = section.GetItemNavigates (item) ?
					             UITableViewCellAccessory.DisclosureIndicator :
					             UITableViewCellAccessory.None;
				}

				if (section.GetItemEnabled (item)) {
					var cmd = item as Command;
					if (cmd != null) {
						theme.ApplyCommand (cell);
					}
					cell.SelectionStyle = UITableViewCellSelectionStyle.Blue;
				}
				else {
					cell.TextLabel.TextColor = UIColor.LightGray;
					cell.SelectionStyle = UITableViewCellSelectionStyle.None;
				}
			}
Exemple #4
0
            public void FormatCell(PFormCell cell, PFormSection section, object item)
            {
                var theme = Theme.Current;

                theme.Apply(cell);

                var itemTitle = section.GetItemTitle(item);

                cell.TextLabel.Text = itemTitle;
                cell.TextLabel.AccessibilityLabel = itemTitle;
                cell.TextLabel.BackgroundColor    = UIColor.Clear;

                var display = section.GetItemDisplay(item);

                if (display != PFormItemDisplay.Title)
                {
                    cell.DetailTextLabel.Text = section.GetItemDetails(item) ?? "";
                    if (display == PFormItemDisplay.TitleAndValue)
                    {
                        cell.DetailTextLabel.TextColor = UIApplication.SharedApplication.KeyWindow.TintColor;
                    }
                }

                var imageUrl = section.GetItemImage(item);

                if (string.IsNullOrEmpty(imageUrl))
                {
                    cell.ImageView.Image = null;
                }
                else
                {
                    UIImage image;
                    if (!imageCache.TryGetValue(imageUrl, out image))
                    {
                        image = UIImage.FromBundle(imageUrl);
                        imageCache.Add(imageUrl, image);
                    }
                    cell.ImageView.Image = image;
                }

                if (section.GetItemChecked(item))
                {
                    cell.Accessory = UITableViewCellAccessory.Checkmark;

                    theme.ApplyChecked(cell);
                }
                else
                {
                    cell.Accessory = section.GetItemNavigates(item) ?
                                     UITableViewCellAccessory.DisclosureIndicator :
                                     UITableViewCellAccessory.None;
                }

                if (section.GetItemEnabled(item))
                {
                    var cmd = item as Command;
                    if (cmd != null)
                    {
                        theme.ApplyCommand(cell);
                    }
                    cell.SelectionStyle = UITableViewCellSelectionStyle.Blue;
                }
                else
                {
                    cell.TextLabel.TextColor = UIColor.LightGray;
                    cell.SelectionStyle      = UITableViewCellSelectionStyle.None;
                }
            }