I have created a custom UITableView Cell class for my UITableView. However, I cannot set the values within the cell for some reason. As in the values such as userName and userImage do not show when the table is loaded. This problem has been going for a few days. Below is my code, I used dummy values for sake of simplicity. If someone can please let me know what I am doing wrong, it would be appreciated.
Thanks!
CODE
CustomCell.h
@interface CustomCell : UITableViewCell
{
IBOutlet UILabel *userName;
IBOutlet UIImageView *userImage;
}
@property(strong,nonatomic) IBOutlet UILabel *userName;
@property(strong,nonatomic) IBOutlet UIImageView *userImage;
@end
CustomCell.m
#import "CustomCell.h"
@interface CustomCell ()
@end
@implementation CustomCell
@synthesize userName;
@synthesize userImage;
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
// Custom initialization
NSArray *nibArray= [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
self= [nibArray objectAtIndex:0];
}
return self;
}
-(void) setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
@end
ViewController.m (The class with the UITableView that calls the custom cell)
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
CustomCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.userName=@"Adam Scott";
cell.userImage=[UIImage imageNamed:@"adam.png"];
return cell;
}