-1

my code is:

- (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];

        }
}

i am getting error as follows

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) 
hhanesand
  • 990
  • 11
  • 28
Mano Chitra R
  • 231
  • 1
  • 3
  • 13
  • That's not an error during build. That's a runtime exception when the app is actually running. – rmaddy Feb 16 '15 at 06:38
  • yes error during running the app – Mano Chitra R Feb 16 '15 at 06:42
  • Try to use your property not the sent instance. – Ashraf Tawfeeq Feb 16 '15 at 08:13
  • Your code doesn't seem to have anything to do with your exception. The exception says that you're sending the message refreshControl to a instance of your class ViewController. Have you exception breakpoints enabled? This should show you the line where the exception is thrown. – Pierre Feb 16 '15 at 08:59
  • As Pierre mentioned, it would help if you could show us more of your code, because the section you have provided to us does not seem to be the cause of your problem. If you're having trouble finding out where the exception is being thrown, check out [this stack overflow](http://stackoverflow.com/a/7703570/4080860) answer for information on how to enable exception breakpoints which will show you what code is crashing, or look around in your code for `refreshControl` and post it so we can help you. – hhanesand Feb 16 '15 at 16:15

2 Answers2

1

I think your TableView may be getting released after you create it and the method ends. You probably need to create an instance variable inside in View controller that references it.

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

Then remove the associated cell from the Table View

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

May help you..

Hima
  • 1,249
  • 1
  • 14
  • 18
Chandan kumar
  • 1,074
  • 12
  • 31
  • use this link may help you.. http://stackoverflow.com/questions/5454708/nsinternalinconsistencyexception-invalid-number-of-rows – Chandan kumar Feb 16 '15 at 08:04
-1

Try this

-(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];
}
Bhargav
  • 139
  • 3
  • 12
  • What does this have to do with the exception? And why reload the table? Just remove the one row. – rmaddy Feb 16 '15 at 06:43
  • 1
    It's necessary to reload the tableView because you are deleting object from an array so no of cells must be recount that's why your application gives you runtime error. Once you reload the table it recreates the number of cells. – Bhargav Feb 16 '15 at 06:47
  • That's simply no true. If the number of rows didn't match, it would be a completely different error. And you do not have to reload the table. Just deleting the one row is fine. The code posted in the question is fine. Your answer has nothing to do with the posted exception. – rmaddy Feb 16 '15 at 06:48
  • do u want to delete all rows? – Bhargav Feb 16 '15 at 06:50
  • i m getting delete option but when i click ,it gives that error – Mano Chitra R Feb 16 '15 at 06:55
  • above is my final code. this works for me when I swipe the screen it shows me a red delete button when I click this button the record gets deleted. I hope it also works for you. – Bhargav Feb 16 '15 at 07:02
  • now im getting this error Assertion failure in -[UITableView _endCellAnimationsWithContext:], ** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (9) must be equal to the number of rows contained in that section before the update (9), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section(0 moved in, 0 moved out) – Mano Chitra R Feb 16 '15 at 07:09
  • can u send me the whole project. bhargav5530@gmail.com – Bhargav Feb 16 '15 at 07:27