'-[__NSArrayM _fastCStringContents:]: 无法识别的选择器发送到实例

jck*_*kly 2 objective-c uitableview nsstring nsarray ios

当我尝试将对象添加到可变数组时,我不断收到无法识别的选择器,当在表视图中选择单元格时,我尝试向可变数组添加和删除项目,这是我的代码:

@interface SomeViewController
  @property (nonatomic, strong) NSMutableArray *selectedItems;
@end
Run Code Online (Sandbox Code Playgroud)

查看已加载:

-(void)viewDidLoad {

    [super viewDidLoad];

    self.selectedItems = [[NSMutableArray alloc] init];
}
Run Code Online (Sandbox Code Playgroud)

选择单元格:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    MyCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    [self.selectedItems addObject:[NSString stringWithFormat:@"%@", cell.contactID]];
Run Code Online (Sandbox Code Playgroud)

MyCell 文件上的联系人 ID 属性为:

@property (strong, nonatomic) NSString *contactID;
Run Code Online (Sandbox Code Playgroud)

我不断收到此错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM _fastCStringContents:]: unrecognized selector sent to instance 0x7fc3dd1091b0'
Run Code Online (Sandbox Code Playgroud)

gna*_*729 8

在某个地方,您有一个您认为是字符串的对象,而实际上它是一个可变数组 - 这就是错误消息所说的内容。在异常上设置一个断点,这应该准确地告诉您异常发生的位置,然后找到您认为是字符串的数组。