【发布时间】:2016-10-11 02:20:48
【问题描述】:
当我尝试将对象添加到我的可变数组时,我不断得到一个无法识别的选择器,当我在我的表格视图中选择一个单元格时,我试图向可变数组添加和删除项目,这是我的代码:
@interface SomeViewController
@property (nonatomic, strong) NSMutableArray *selectedItems;
@end
视图确实加载了:
-(void)viewDidLoad {
[super viewDidLoad];
self.selectedItems = [[NSMutableArray alloc] init];
}
选择单元格:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[self.selectedItems addObject:[NSString stringWithFormat:@"%@", cell.contactID]];
MyCell 文件上的联系人 ID 属性为:
@property (strong, nonatomic) NSString *contactID;
我不断收到此错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM _fastCStringContents:]: unrecognized selector sent to instance 0x7fc3dd1091b0'
【问题讨论】:
-
你为什么使用
[self.selectedItems addObject:[NSString stringWithFormat:@"%@", cell.contactID]];而不是[self.selectedItems addObject:cell.contactID];?尝试更改它 -
我在这里查看了一些问题,发现它可能会有所帮助。所以我试了一下。我已经尝试了您建议的两种变体,并且都返回了我得到的完全相同的错误。
-
contactID在您的情况下每次都不是字符串。尝试调试您的单元格数据。添加exception breakpoint。
标签: ios objective-c uitableview nsstring nsarray