[__NSCFString name]: unrecognized selector sent to instance
而崩溃。我无法弄清楚我的代码中的缺陷,所以我想我会把它带到这里,而不是花更多时间调试错误的方向。
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
if (sourceIndexPath.section == 0) {
Athlete *athlete = players[sourceIndexPath.row];
NSLog(@"sta count: %lu", (unsigned long)[players count]);
if (athlete != nil) {
if (destinationIndexPath.section == 1) {
[players removeObjectAtIndex:sourceIndexPath.row];
[benched insertObject:athlete.name atIndex:destinationIndexPath.row];
}else if (destinationIndexPath.section == 2){
[players removeObjectAtIndex:sourceIndexPath.row];
[reserved insertObject:athlete.name atIndex:destinationIndexPath.row];
}
}
} else if (sourceIndexPath.section == 1) {
Athlete *athlete = benched[sourceIndexPath.row];
NSLog(@"Benched count: %lu", (unsigned long)[benched count]);
if (destinationIndexPath.section == 0) {
[benched removeObjectAtIndex:sourceIndexPath.row];
[players insertObject:athlete.name atIndex:destinationIndexPath.row];
}else if (destinationIndexPath.section == 2){
[benched removeObjectAtIndex:sourceIndexPath.row];
[reserved insertObject:athlete.name atIndex:destinationIndexPath.row];
}
}else if (sourceIndexPath.section == 2) {
Athlete *athlete = reserved[sourceIndexPath.row];
NSLog(@"Res count: %lu", (unsigned long)[reserved count]);
NSLog(@"From starter");
if (destinationIndexPath.section == 1) {
NSLog(@"To bench");
[reserved removeObjectAtIndex:sourceIndexPath.row];
[benched insertObject:athlete.name atIndex:destinationIndexPath.row];
}else if (destinationIndexPath.section == 0){
NSLog(@"To reserves");
[reserved removeObjectAtIndex:sourceIndexPath.row];
[players insertObject:athlete.name atIndex:destinationIndexPath.row];
}
/* [players removeObjectAtIndex:sourceIndexPath.row];
[self.tableView reloadData];
[players insertObject:athlete.name atIndex:destinationIndexPath.row];*/
}
}
注意:
*所有NSMutableArrays都是(nonatomic, retain)
*确切的失败线是[NSMutableArray insertObject:athlete.name atIndex: destinationIndexPath.row];
* Athlete *athlete
是具有NSString属性的对象,如athlete.name
。
答案 0 :(得分:1)
错误消息表示您正试图在name
上调用NSString
方法。
这意味着您的athlete
为NSString
而不是Athlete
。
您可以在调试器中检查对象类型,或使用NSLog("%@ - %@", [athlete class], athlete)
进行记录。