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

  • Home
  • SEARCH
  • 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 7552583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:47:37+00:00 2026-05-30T10:47:37+00:00

Update for code: Following on Matthew’s answer I tried correcting my code to be

  • 0

Update for code: Following on Matthew’s answer I tried correcting my code to be more correct. Now the code does delete the cell but also crashes and gives an error:

* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]’

The code below is from an action called checkboxTapped which is in my CustomCell code. Once action is fired it gives the error. I figured out that my indexPath is equal to NULL, and thats most likely the issue. But I don’t know how to fix it.

[self.textLabel setTextColor:[UIColor grayColor]];
[self.detailTextLabel setTextColor:[UIColor grayColor]];

parent = [[ViewController alloc] init];

db = [[DataObject alloc] init];
NSIndexPath *indexPath = [[parent tableView] indexPathForSelectedRow];

[[parent array] removeObjectAtIndex:[indexPath row]];
[db deleteTaskAtIndex:[indexPath row]];

[[parent tableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

[db release];
[parent release];

Old: I looked through my code and I printed my array I was using and it appears to be fine, yet this error still persists.

* Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[__NSArrayM removeObjectAtIndex:]: index 1 beyond bounds [0 .. 0]’

My guess was that it had something to do with my indexPath but it doesn’t make much different how much I change it.

-(void)checkboxTapped:(id)sender
{
    [sender setSelected:YES];

    [self.textLabel setTextColor:[UIColor grayColor]];
    [self.detailTextLabel setTextColor:[UIColor grayColor]];

    parent = [[ViewController alloc] init];
    UITableView *tableView = parent.tableView;
    NSMutableArray *array = [[NSMutableArray alloc] initWithArray:parent.array];
    [parent release];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];

    [array removeObjectAtIndex:[indexPath row]];
    [db deleteTaskAtIndex:[indexPath row]];    
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];

    [array release];

    [tableView endUpdates];
    [tableView reloadData];
}
  • 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-30T10:47:38+00:00Added an answer on May 30, 2026 at 10:47 am

    In your code [indexPath row] is going to return the value of [array count]. That’s unlikely to be what you want. If your array has zero objects in it, you are going to attempt to remove the object at index 0. But there will be no objects and you’ll get an error. If your array has 1 object in it, you’re going to attempt to remove the object at index 1. Again, that will fail, because there is no object at index 1, just one object at index 0.

    If you want to remove the last object in an array you need to use an index that is count-1. You may also need to check to see if the array is empty, if that case can occur.

    Updated in response to follow up in comment

    You don’t want to do anything indexPathWithIndex. As a first step, try modifying your code along the following lines:

    -(void)checkboxTapped:(id)sender
    {
        [sender setSelected:YES];
    
        [self.textLabel setTextColor:[UIColor grayColor]];
        [self.detailTextLabel setTextColor:[UIColor grayColor]];
    
        parent = [[ViewController alloc] init];  // looks very odd - is an instance of this viewController active when the checkBox is tapped? If so, you don't want to create a new one, you want to access the existing one
        UITableView *tableView = parent.tableView;
        [parent release];  // this looks very dicey - when you release the parent, won't it release the tableView too?!
    
        int lastRow = [array count] - 1;
        if (lastRow == 0)
        {
             return; // bail if there are no rows in the table
        }
    
        NSMutableArray *array = [[NSMutableArray alloc] initWithArray:parent.array];
        [array removeObjectAtIndex: lastRow];  // not clear this will do anything as the reference to array is discarded later
    
        [db deleteTaskAtIndex: lastRow];   
    
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow: lastRow inSection:1]; 
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
    
        [array release];
    
    // [tableView endUpdates];  // there's no matching beginUpdates and you're only do one change operation anyway - leave this out
    
    // [tableView reloadData]; // if you leave this line in, you won't see the delete animation - if you just want to delete one row, you wouldn't normally use reloadData, at least not if you want the animation
    }
    

    All this said, it looks as if there are other things going on here.

    What’s happening with array? You create this, remove an item from it and the discard the pointer to it. Is that what you really want to do. A more common pattern would be to get the pointer to the array from the other object and remove the item at the end of it here.

    It’s not clear from your code how you are updating the table’s data source. When using deleteRowsAtIndexPaths:withRownAnimation you need to make sure the table’s data source will return one row less than it did last time it was asked with tableView:numberOfRowsInSection:. From your code it’s not clear how the tableView dataSource is going to know there’s one less item, unless, perhaps, it’s looking at whatever it is that db is pointing to in order to find this out.

    More fundamentally, with a typical design pattern the tableView is going to be released when you release the parent view, so whatever it points to after `[parent release]’ is going to do something undefined and is likely to crash at least some of the time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code UPDATE is working but DELETE is not working. When I
I'm using the following code to update a DataGridView's cell value. This is called
The following code should update a hidden field on form submit but it simply
I am using the following code to update the data in my datagrid. But
Right now I am using the following code to update a TextView txtMain.setText(new text);
I can update code correctly, but cannot commit code. I get the following error
I have the following code: UPDATE myTable SET Col1 = @Value However, I have
I'm running the following code to update the database according to the data I
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
the following code (from a database object created for each new view): -(void)update:(NSString *)queryText{

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.