[__NSCFString name]:发送到实例的无法识别的选择器

时间:2015-01-28 04:53:11

标签: ios objective-c uitableview nsmutablearray nsindexpath

奇怪的是,我的应用程序有一个带有三个部分的UITableView,每个部分都由一个单独的数组填充。最终目标是能够将单元格从一个区域移动到另一个区域,因此我在UITableViewController中编写了“逻辑”。不幸的是,如果我尝试将单元格移动到空白区域,它会因错误[__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

1 个答案:

答案 0 :(得分:1)

错误消息表示您正试图在name上调用NSString方法。

这意味着您的athleteNSString而不是Athlete

您可以在调试器中检查对象类型,或使用NSLog("%@ - %@", [athlete class], athlete)进行记录。