未捕获的异常' NSInvalidArgumentException'运行时错误

时间:2015-02-16 06:31:35

标签: ios objective-c unrecognized-selector

我的代码是:

- (void)  tableView:(UITableView *)tableView
 commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
  forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (editingStyle == UITableViewCellEditingStyleDelete){
        /* First remove this object from the source */
        [self.allRows removeObjectAtIndex:indexPath.row];

        /* Then remove the associated cell from the Table View */
       [tableView deleteRowsAtIndexPaths:@[indexPath]
                        withRowAnimation:UITableViewRowAnimationFade];

        }
}

我收到如下错误

2015-02-16 11:57:32.413 SimpleTable[1590:45462] -[ViewController refreshControl]: unrecognized selector sent to instance 0x7fa1d2d936c0
2015-02-16 11:57:32.415 SimpleTable[1590:45462] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController refreshControl]: unrecognized selector sent to instance 0x7fa1d2d936c0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d738f35 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010d3d1bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010d74004d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010d69827c ___forwarding___ + 988
    4   CoreFoundation                      0x000000010d697e18 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x000000010db268be -[UIApplication sendAction:to:from:forEvent:] + 75
    6   UIKit                               0x000000010db268be -[UIApplication sendAction:to:from:forEvent:] + 75
    7   UIKit                               0x000000010dc2d410 -[UIControl _sendActionsForEvents:withEvent:] + 467
    8   UIKit                               0x000000010dc2c7df -[UIControl touchesEnded:withEvent:] + 522
    9   UIKit                               0x000000010db6c308 -[UIWindow _sendTouchesForEvent:] + 735
    10  UIKit                               0x000000010db6cc33 -[UIWindow sendEvent:] + 683
    11  UIKit                               0x000000010db399b1 -[UIApplication sendEvent:] + 246
    12  UIKit                               0x000000010db46a7d _UIApplicationHandleEventFromQueueEvent + 17370
    13  UIKit                               0x000000010db22103 _UIApplicationHandleEventQueue + 1961
    14  CoreFoundation                      0x000000010d66e551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x000000010d66441d __CFRunLoopDoSources0 + 269
    16  CoreFoundation                      0x000000010d663a54 __CFRunLoopRun + 868
    17  CoreFoundation                      0x000000010d663486 CFRunLoopRunSpecific + 470
    18  GraphicsServices                    0x0000000110d079f0 GSEventRunModal + 161
    19  UIKit                               0x000000010db25420 UIApplicationMain + 1282
    20  SimpleTable                         0x000000010cea27d3 main + 115
    21  libdyld.dylib                       0x000000010fcc8145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

2 个答案:

答案 0 :(得分:1)

我认为您的TableView可能会在您创建后发布,并且方法结束。您可能需要在View控制器中创建一个引用它的实例变量。

@property (strong, nonatomic) IBOutlet UITableView *tablview;

然后从表视图中删除关联的单元格

[self.tablview  deleteRowsAtIndexPaths:@[indexPath]
                        withRowAnimation:UITableViewRowAnimationFade];

可以帮助你..

答案 1 :(得分:-1)

试试这个

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{
    //remove the row from data model
    [tableData removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}