Reputation: 2818
I'm trying to make a tableview with customized cells.
I've created 2 files .m and .h that refer to my class CustomCell. Here is the code :
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
{
IBOutlet UIImageView *miniLogo;
IBOutlet UILabel *cellText;
IBOutlet UIButton *deleteButton;
}
@property (strong, nonatomic) IBOutlet UIImageView *miniLogo;
@property (strong, nonatomic) IBOutlet UILabel *cellText;
@property (strong, nonatomic) IBOutlet UIButton *deleteButton;
@end
-------------------------------------------------------------
#import "CustomCell.h"
@implementation CustomCell
@synthesize miniLogo,cellText, deleteButton;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
}
/*
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}*/
@end
With a .xib file, i've designed my cell, and connected the IBOutlets and set the Identifier for the cell.
In the table with my customized cells, I call the cells in the method tableView:cellForRowAtOndexPath: like this :
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellsIdentifier ];
if (cell == nil){
UIViewController *tempVC = [[UIViewController alloc] initWithNibName:@"CustomCell" bundle:nil];
cell = (CustomCell *)tempVC.view;
}
When I launch my app, the labels display the texts set, and the image views show the right images. But the buttons don't appear. In fact, when setting break points, I seen that address for my buttons are always 0x00000000 (means that my buttons aren't initiated).
Can someone help me to solve this problem please.
Upvotes: 1
Views: 162
Reputation: 2818
I've found the problem.
In he viewDidLoad I was doing :
UINib *cellNib = [UINib nibWithNibName:@"myCells" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:CellsIdentifier];
But because I have changed my .xib name, I wasn't loading the right interface. What is strange is that I don't have any nib named "myCells". Maybe I should have perform a "clean" on my project...
Upvotes: 1