Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6133149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:11:27+00:00 2026-05-23T17:11:27+00:00

i wrote the following snippet according to The iPhone Developer’s Cookbook C5 – Tables

  • 0

i wrote the following snippet according to The iPhone Developer’s Cookbook C5 – Tables 07a – Delete:

-(void)viewDidLoad{
    history=[[NSMutableArray alloc]initWithObjects:@"a",@"b",@"c",@"d",@"e",nil];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"return %d",[history count]);
    return [history count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[self.tableView dequeueReusableCellWithIdentifier:@"any-cell"];
    if(cell==nil)
        cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:@"any-cell"]autorelease];
    cell.textLabel.text=[history objectAtIndex:[indexPath row]];
    cell.textLabel.textColor=[UIColor blackColor];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"[history count]=%d",[history count]);
    NSLog(@"[indexPath row]=%d",[indexPath row]);
    [history removeObjectAtIndex:[indexPath row]];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

after building, i pressed the “edit” button on the navigation bar and there showed a red “-” for deletion. but nothing on screen changed. after multiple “-” hits, the app crashed. the output is:

> 2011-07-13 05:16:34.128 test[13141:207] return 5 2011-07-13
> 05:16:37.909 test[13141:207] [history count]=5 2011-07-13 05:16:37.910
> test[13141:207] [indexPath row]=0 2011-07-13 05:16:39.069
> test[13141:207] [history count]=4 2011-07-13 05:16:39.070
> test[13141:207] [indexPath row]=0 2011-07-13 05:16:39.653
> test[13141:207] [history count]=3 2011-07-13 05:16:39.654
> test[13141:207] [indexPath row]=0 2011-07-13 05:16:40.069
> test[13141:207] [history count]=2 2011-07-13 05:16:40.070
> test[13141:207] [indexPath row]=0 2011-07-13 05:16:40.509
> test[13141:207] [history count]=1 2011-07-13 05:16:40.510
> test[13141:207] [indexPath row]=0 2011-07-13 05:16:41.581
> test[13141:207] [history count]=0 2011-07-13 05:16:41.582
> test[13141:207] [indexPath row]=0 2011-07-13 05:16:41.589
> test[13141:207] *** Terminating app due to uncaught exception
> 'NSRangeException', reason: '*** -[NSMutableArray
> removeObjectAtIndex:]: index 0 beyond bounds for empty array'
> *** Call stack at first throw: (
>     0   CoreFoundation                      0x00db3be9 __exceptionPreprocess + 185
>     1   libobjc.A.dylib                     0x00f085c2 objc_exception_throw + 47
>     2   CoreFoundation                      0x00dacadf -[__NSArrayM removeObjectAtIndex:] + 415
>     3   Â∞èËaæáßò‰π¶                        0x00004614 -[CallHistory tableView:commitEditingStyle:forRowAtIndexPath:] + 182
>     4   UIKit                               0x003262ea -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 101
>     5   UIKit                               0x002bca6e -[UIApplication sendAction:to:from:forEvent:] + 119
>     6   UIKit                               0x0034b1b5 -[UIControl sendAction:to:forEvent:] + 67
>     7   UIKit                               0x0034d647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
>     8   UIKit                               0x0034c1f4 -[UIControl touchesEnded:withEvent:] + 458
>     9   UIKit                               0x002e10d1 -[UIWindow _sendTouchesForEvent:] + 567
>     10  UIKit                               0x002c237a -[UIApplication sendEvent:] + 447
>     11  UIKit                               0x002c7732 _UIApplicationHandleEvent + 7576
>     12  GraphicsServices                    0x016e9a36 PurpleEventCallback + 1550
>     13  CoreFoundation                      0x00d95064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
>     14  CoreFoundation                      0x00cf56f7 __CFRunLoopDoSource1 + 215
>     15  CoreFoundation                      0x00cf2983 __CFRunLoopRun + 979
>     16  CoreFoundation                      0x00cf2240 CFRunLoopRunSpecific + 208
>     17  CoreFoundation                      0x00cf2161 CFRunLoopRunInMode + 97
>     18  GraphicsServices                    0x016e8268 GSEventRunModal + 217
>     19  GraphicsServices                    0x016e832d GSEventRun + 115
>     20  UIKit                               0x002cb42e UIApplicationMain + 1160
>     21  Â∞èËaæáßò‰π¶                        0x0000229c main + 106
>     22  Â∞èËaæáßò‰π¶                        0x00002229 start + 53
>     23  ???                                 0x00000001 0x0 + 1 ) 
terminate called after throwing an instance of 'NSException'

The NSLog showed that history (which is a NSMutableArray) have been changed actually. I built The iPhone Developer’s Cookbook C5 – Tables 07a – Delete and found a similar crash happened, where tableView: numberOfRowsInSection: was called only once. but DeleteMeController in Beginning iPhone 3 Development 09 Nav successfully deleted a row and tableView: numberOfRowsInSection: was called every time once tableView: commitEditingStyle: forRowAtIndexPath: was called. iPhone Developer’s Cookbook’s code was written manually, and Beginning iPhone 3 Development used Interface Builder.

Any clues on what’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:11:28+00:00Added an answer on May 23, 2026 at 5:11 pm
    -(void)tableView:(UITableView *)tableView commitEditingStyle: UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
            if (editingStyle == UITableViewCellEditingStyleDelete) { 
                    [history removeObjectAtIndex:indexPath.row];
                    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
            [tableView endUpdates];
            [tableView reloadData];
           }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following code snippet: void foo() { struct _bar_ { int a;
I wrote the following snippet in order to handle errors. (Page.php gets included in
When I wrote the following snippet for experimenting purposes, it raised the hover-error (see
I wrote the following code snippet in VS2010: #pragma once #include stdafx.h #ifndef SECURITY_WIN32
I wrote following function void validateUser(void) { string uName; string uPassword; char c; map
I am using g++ to compile some code. I wrote the following snippet: bool
The following snippet is from a little app I wrote using the Qt framework.
I have the following snippet of C code: #include <stdio.h> void main(){ int a
I wrote the following snippet to get rid of excessive spaces in slabs of
In the following snippet, you can see my two collatz functions I wrote in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.