【发布时间】:2015-08-23 10:52:15
【问题描述】:
我有一个“UITableView”,应该加载一个自定义“UITableViewCell”。当用户触摸其中一个单元格时,触摸的单元格将被另一个自定义单元格替换,并带有额外的信息标签。
但是,当用户触摸单元格时,应用程序会崩溃。它引发了以下异常:
'NSInvalidArgumentException',原因:'-[simplefiedCell cellInfo]: unrecognized selector sent to instance 0x7fb5b2f3d950'
(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;
}
以及我在(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];
有人知道发生了什么吗?感谢任何帮助!
【问题讨论】:
标签: ios objective-c uitableview unrecognized-selector