Hi, In my program I'm creating a couple of custom UIViewCells loaded from a nib file:
[[NSBundle mainBundle] loadNibNamed:@"CustomCells" owner:self options:nil];
Once they're loaded i set them up and return from the function:
if (indexpath.row == 1) {
[nibTextInputer setupWithName:@"notes" ...];
return nibTextInputer;
} else {
[nibSelectInputer setupWithName:@"your_choice" ...];
return nibSelectInputer;
};
Where nibTextInputer is of my class (AFTextInputer) and nibSelectInputer is of my other class (AFTextInputer). Both classes subclass from UITableViewCell.
It all works fine, BUT breaks when I add caching to that:
Boolean inCache = false;
if (indexPath.row == 1) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"nibTextInputer"];
if (cell != nil) {
NSLog(@"%@", [cell description]); // prints out ok, correct type.
nibTextInputer = (AFTextInputer*) cell;
inCache = true;
};
};
if (!inCache) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCells" owner:self options:nil];
}
Once I add the above EXC_BAD_ACCESS starts appearing in random places, usually with no additional information and sometimes with this error:
-[CALayer prepareForReuse]: unrecognized selector sent to instance
or even
-[UIImage prepareForReuse]: unrecognized selector sent to instance
The location of EXC_BAD_ACCESS is seemingly random. Sometimes it's right after "dequeue", sometimes outside of the function..
I guess the problem lies within my implementation of custom UIViewCells, but I have no idea where to start looking..
Ideas?