views:

38

answers:

1

Hi Everybody,

I'm trying to create my own custom cell, but for some reason, it isn't appearing. I read a lot of example, the code looks like (at least for me) equal to others. I used the interface builder to recreate it (I deleted the Default View, add a TableViewCell, put Identifier = CustomCell, and wire up the Label with valueLabel).

Can comeone help me?

Thanks in advance.

//CustomCell.h
#import <UIKit/UIKit.h>


@interface CustomCell : UITableViewCell {
    IBOutlet UILabel *valueLabel;
}
@property(nonatomic, retain) IBOutlet UILabel *valueLabel;

@end

//CustomCell.C
#import "CustomCell.h"
@implementation CustomCell

@synthesize valueLabel;

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

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)dealloc {
    [super dealloc];
}

@end


//Where I'm trying to use this cell. Here I imported the .h file (#import "CustomCell.h"):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    cell.valueLabel.text = @"Any text";

    return cell;
}
A: 

Your cellForRowAtIndexPath method belongs in the table view controller? Is that where it is located?

Jeff
yes, cellForRowAtIndexPath belongs to another file (ViewController.C)
Claudio