0

I have a custom cell in UITableView.I have hooked it to a class(DocumentCell)in Identity inspector.The DocumentCell.h class looks like this:

@interface DocumentCell : UITableViewCell
   @property(nonatomic,retain) IBOutlet UILabel *lblDocName;
@end

The DocumentCell.m file looks like this:

@implementation DocumentCell

@synthesize lblDocName;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}
@end

And here's the code for "cellForRowAtIndexPath":

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //static NSString *CellIdentifier = @"DocumentCell";
    DocumentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DocumentCell"];

    if (cell == nil)
    {
        cell = [[[DocumentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DocumentCell"] autorelease];

    }
    NSLog(@"cell text=%@",[self.myDocList objectAtIndex:indexPath.row]);
    cell.lblDocName.text = [self.myDocList objectAtIndex:indexPath.row];
    return cell;
}

I am using storyboard.I have hooked the IBOutlet for the cell with the label.The NSLog statement shows the text that should be displayed but the actual table doesn't display the text in the cell.Any idea to solve this?

Popeye
  • 11,839
  • 9
  • 58
  • 91
user1550951
  • 369
  • 2
  • 9
  • 26

1 Answers1

1

A couple of things to check:

  • Go into the custom cell NIB (DocumentCell), and check that you have set the 'Custom class' of the custom cell to be DocumentCell, and that it's not of the default UITableViewCell class. You need to do this at the UITableViewCell level in the NIB, the 'File Owner' class should be NSObject. (I think you say you've done this, but worth checking)

  • Check that you've hooked up the lblDocName label to the corresponding IBOutlet.

Snips
  • 6,575
  • 7
  • 40
  • 64
  • :-I have checked all that(again!).But it still doesn't display the text.The NSLog,however,displays the text.Anything else I should be looking at? – user1550951 Aug 21 '12 at 08:33
  • Well, I always prefer to use the form, [cell.lblDocName setText:[self.myDocList objectAtIndex:indexPath.row]]; to ensure that the label string is retained. – Snips Aug 21 '12 at 08:50