In CustomCell.m I define init method where I want to load cell from the IB:
- (id)init {
self = [super init];
if (self) {
NSArray *nib =[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
self = [nib objectAtIndex:0];
}
return self;
}
In the MyTableViewController.m in the method cellForRowAtIndexPath I initialize my custom cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell=[[CustomCell alloc]init];
return cell;
}
Everything works as I expected but when I did Product -> Analyse I get
Returning 'self' while it is not set to the result of '[(super or self) init...]'
What am I doing wrong?
You are overwriting
self(returned fromsuper init) with the object returned from your array. If you want to load a custom cell from a nib, do it in your cellForRowAtIndexPath method, or create a convenience class method on your custom cell that loads from the nib:In your cellForRowAtIndexPath:
In your cell’s implementation:
EDIT – changed method name since new* indicates that a retained object will be returned.