NSMutablearray显示: - [__ NSDictionaryM removeObjectAtIndex:]:发送到实例的无法识别的选择器

时间:2015-01-06 14:24:38

标签: ios objective-c nsmutablearray

我正在尝试从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];


 }

1 个答案:

答案 0 :(得分:3)

以下是错误的原因。

[orderDetails[cellIndexPath.section] removeObjectAtIndex:cellIndexPath.row];

orderDetails是一个数组,[orderDetails [cellIndexPath.section]不是。

orderDetails [x]是从JSON中提取的对象,在本例中是JONE的字典类型。