Forum Xamarin Xamarin.iOS

Is it possible to create a fully-programmatic custom UITableViewCell without having to use .xib?

Programming natively with Swift, I can create a custom table view cell by inheriting UITableViewCell and overriding methods such as init() - But I'm in a world of pain trying to replicate this in Xamarin.

I don't want to have to rely on a xib to create the cell, I'd much rather be able to subclass it in the same way that I can subclass a UIView and override the draw() etc.

Can anyone point me in the direction of examples? Or does almost everyone subscribe to the WYSIWYG way of doing things?

Best Answer


  • Thanks Alex.

    I found an example of a programmatically created UICollectionViewCell and noticed that using [Export("initWithFrame:")] with the default constructor allowed me to basically treat the cell like a standard UIView. Might help others with a similar question:

        public static readonly NSString CellId = new NSString("CustomCell");
        public CustomCell(RectangleF frame) : base(frame) 
        public override void Draw(CGRect rect)
        // ... etc.
  • FinHorsleyFinHorsley USMember ✭✭

    Do i still need to use

    if(cell == null) { //instantiate new cell }
    now that iOS 11/Swift 4 has been released? I was reading the Apple docs, and it seemed as if i didn't

    at the moment I am just dequeuing a cell and returning it, although I am getting error then updating the cell.

Sign In or Register to comment.