I have a 'UITableView' which should be loaded with one Custom 'UITableViewCell'. When the user touch one of the cells, the touched cell is replaced by another custom cell, with a extra Label of information.
However, the app is crashing when the user touch the cell. It's raising the following exception:
'NSInvalidArgumentException', reason: '-[simplefiedCell cellInfo]: unrecognized selector sent to instance 0x7fb5b2f3d950'
Where is my code for (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
:
if(indexPath.row == self.selectedCell) {
regularCell *cell = (regularCell *)[tableView dequeueReusableCellWithIdentifier:cellID1];
[cell.cellInfo setText:@"Some temporally text to test this code"];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"regularCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}else{
simplefiedCell *cell = (simplefiedCell *)[tableView dequeueReusableCellWithIdentifier:cellID2];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"simplefiedCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
switch (indexPath.row) {
case 0:
[cell.cellTopic setText:@"Text1"];
break;
case 1:
[cell.cellTopic setText:@"Text2"];
break;
case 2:
[cell.cellTopic setText:@"Text3"];
break;
case 3:
[cell.cellTopic setText:@"Text4"];
break;
case 4:
[cell.cellTopic setText:@"Text5"];
break;
case 5:
[cell.cellTopic setText:@"Text6"];
break;
default:
break;
}
return cell;
}
And where the simple code that I use inside (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
:
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == self.selectedCell)
self.selectedCell = -1;
else
self.selectedCell = indexPath.row;
[self.tableView reloadData];
Does anyone know what is going on? Appreciate any help!
At a glance, I suspect that the problem is not in the code you've pasted above. Chances are either:
If none of those three is the case, then I would suggest searching for the simplified cell class's name—first in the XIB xml file, then in the code—and wherever you find it, ask yourself if it should really be the regular class in that spot instead. Presumably one of them should be.