Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If anyone else has this problem, you can download a working example project here: <a href="https://github.com/ijoshsmith/CustomCellDemo" rel="nofollow">https://github.com/ijoshsmith/CustomCellDemo</a></p> <p>Otherwise, here are the instructions:</p> <p>There are a few ways of doing this that I know of.</p> <p>Assuming the following names and file structure</p> <pre><code>-UITableCellCustomClass.h -UITableCellCustomClass.m -UITableCellCustomClass.xib -UITableViewClass.h -UITableViewCustomClass.m -UITableViewCustomClass.xib </code></pre> <p>With Interface Builder, to create a custom table cell you need to do this:</p> <p>1.) Create a custom table cell from a NIB (as you have done) which inherits from UITableViewCell</p> <p>2.) Unhook the "File's Owner" in IB for your custom table cell class and point it at the table class which you are wanting the cell to appear in e.g. change it to UITableViewCustomClass. </p> <p>3.) Click the table cell in your IB screen and go to the field that says UITableViewCell and change it to inherit from your custom table cell class e.g. UITableCellCustomClass</p> <p>4.) MAke sure you have created all the fields and properties as well as outlets for your textfields and made the necessary connections in interfacebuilder between your table cell class and the cell in your custom cell xib (note: NOT the file's owner...)</p> <p>5.) I see you have the "cell identifier" variable there...but just in case you haven't yet, make sure that in your CustomTableCell xib you have changed the cell identifier field to match your custom identifier. </p> <p>That should do it I believe if my memory serves correctly. It looks like you are doing the rest right with your table and setting the properties on the cell. </p> <p>I believe that is all of it. I have it written down in explicit detail someplace because it is such a pain.</p> <p>UPDATE:</p> <p>IF you have five labels, you may need to alter the vertical height of the table rows so that all the labels will show (unless you have a really wide table).</p> <p>Make sure the table has both it's delegate and data source pointed at it's parent class (the one hosting the cell loading logic)</p> <p>You must override this function:</p> <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return YOURCUSTOMROWHEIGHT; } </code></pre> <p>UPDATE: Apparently the above was not sufficient so I'll try again:</p> <p>Try doing this using the following UINib Method:</p> <p>Add this to your UICustomTableView.h class</p> <pre><code>UINib *cellLoader; </code></pre> <p>Next, try the following (assuming you followed all the steps above)...maybe a UINib loader will help? I am pretty sure I covered all the proper steps after looking over my notes. One thing to try is to create a class that extends UIViewController, then delete the view from that, add your table cell and do teh steps above and change the base class to inherit from UITableCellView. </p> <pre><code>static NSString *CellClassName = @"YourCellClassName"; - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { cellLoader = [[UINib nibWithNibName:CellClassName bundle:[NSBundle mainBundle]] retain]; } return self; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Make sure your identifier is set properly in IB CustomCellClass *cell = (CustomCellClass *)[tableView dequeueReusableCellWithIdentifier:CellClassName]; if (!cell) { NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil]; cell = [topLevelItems objectAtIndex:0]; } /* set your cell properties here */ return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload