This question already has answers here:
How can I debug 'unrecognized selector sent to instance' error
(9个答案)
5年前关闭。
我正在尝试从
现在我正在使用SWTableViewCell,我要从中删除特定的单元格,因此要从数组中删除一个条目。
orderDetails是一个数组,而[orderDetails [cellIndexPath.section]不是。
orderDetails [x]是从JSON提取的对象,在本例中为字典类型的Object。
(9个答案)
5年前关闭。
我正在尝试从
NSMutableArray
删除对象,但仍然遇到上述错误。这是我创建和使用数组的方式。#import "CartViewController.h"
@interface CartViewController ()
{
NSMutableArray *orderDetails; //my Array
}
@end
-(void)getCart{
SuccessBlock successBlock = ^(NSData *response){
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
orderDetails = [[NSMutableArray alloc]init];
orderDetails = [responseDict objectForKey:@"orderDetails"];
[self.cartTableView reloadData];
};
FailureBlock failureBlock = ^(NSError *error){
NSLog(@"Failure Block %@",[error localizedDescription]);
};
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@00",BASE_URL,GET_CART]];
HTTPPostRequest *postReq = [[HTTPPostRequest alloc]initWithURL:url successBlock:successBlock failureBlock:failureBlock];
[postReq startRequest];
}
现在我正在使用SWTableViewCell,我要从中删除特定的单元格,因此要从数组中删除一个条目。
#pragma mark - SWTableViewDelegate
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index
{
switch (index) {
case 0:
{
NSLog(@"left button 0 was pressed");
[cell setLeftUtilityButtons:[self leftUndoButton]WithButtonWidth:self.cartTableView.frame.size.width];
[cell showLeftUtilityButtonsAnimated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self deleteCell:cell];
});
break;
}
default:
{
break;
}
}
}
-(void)deleteCell:(SWTableViewCell *)cell{
NSIndexPath *cellIndexPath = [self.cartTableView indexPathForCell:cell];
[orderDetails[cellIndexPath.section] removeObjectAtIndex:cellIndexPath.row];//Exception breakpoint stops here by showing : [__NSDictionaryM removeObjectAtIndex:]: unrecognized selector sent to instance 0x7968afd0
[self.cartTableView deleteRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
最佳答案
这是错误的原因。
[orderDetails[cellIndexPath.section] removeObjectAtIndex:cellIndexPath.row];
orderDetails是一个数组,而[orderDetails [cellIndexPath.section]不是。
orderDetails [x]是从JSON提取的对象,在本例中为字典类型的Object。
10-08 06:29