How do I properly implement INativeElementView?

Ryan3413Ryan3413 USMember ✭✭

public class FeeCellRenderer : ViewCellRenderer, INativeElementView { public Element Element { get { var cell = new FeeViewCell(UITableViewCellStyle.Default, FeeViewCell.Key); return cell.ToView(); } }
I can run the same code if I switch the ListViewCachingStrategy to RetainElement but I want to take advantage of the RecycleElement. I have posted the same question on stackoverflow here.

Best Answer

Answers

  • Ryan3413Ryan3413 USMember ✭✭

    I think I had INativeElementView implemented in the wrong class. I moved it to the view class that represents my cell. Now I get a System.InvalidCastException. Here is my current implementation of INativeElementView:

    public partial class FeeViewCell : UITableViewCell, INativeElementView
    {
    public static readonly NSString Key = new NSString("FeeViewCell");
    public static UINib Nib;

        public Element Element
        { 
            get
            {
                return this.ToView() as Element;
            }
        }
    
        public FeeViewCell(UITableViewCellStyle style, NSString key) : base(style, key)
        { 
            Nib = UINib.FromName("FeeViewCell", NSBundle.MainBundle);
        }
        static FeeViewCell()
        {
            Nib = UINib.FromName("FeeViewCell", NSBundle.MainBundle);
        }
    
        protected FeeViewCell(IntPtr handle) : base(handle)
        {
            // Note: this .ctor should not contain any initialization logic.
        }
    }
    

    What am I missing?

Sign In or Register to comment.