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 559579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:15:09+00:00 2026-05-13T12:15:09+00:00

I have a table that displays data from a single array and organizes the

  • 0

I have a table that displays data from a single array and organizes the items into separate sections based on a set of filters. Each filter has a corresponding section. My UI allows the user to tap a check box embedded in each table cell. This check box sets a “checked” flag which affects which section the item is filtered to. Here’s an example:

  • Section 1
    • Item A
    • Item B
  • Section 2
  • Section “Done”

Tapping the check box next to Item A should cause the table to rearrange to look like this:

  • Section 1
    • Item B
  • Section 2
  • Section “Done”
    • Item A

Below is my code for responding to the check box tap. It figures out which row the check box belongs to and then attempts to create an animation block that deletes the row from its old section and adds a row to the end of the “Done” section. Please keep in mind that the array doesn’t actually change — the way the data is filtered into the sections changes based on the value of the items’ checked properties.

- (IBAction)checkBoxTapped:(id)sender
{
 // Get the table cell
 CheckBoxControl* checkBox = (CheckBoxControl*)sender;

 UITableViewCell* cell = (UITableViewCell*)[[sender superview] superview];
 UITableView* table = (UITableView*)[cell superview];
 NSIndexPath* indexPath = [table indexPathForCell:cell];

 Item* item = [self itemAtRow:[indexPath row] inSection:[indexPath section]];
 item.checked = checkBox.checked;

 Filter* filter = [filters objectAtIndex:DONE_INDEX];
 // We want the new row at the bottom of the "Done" section.
 NSIndexPath* newIndexPath = [NSIndexPath indexPathForRow:[self countItemsWithFilter:filter] inSection:DONE_INDEX];

 [table beginUpdates];
 [table insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
 [table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
 [table endUpdates];
}

This code always throws an exception:

2010-01-13 00:19:44.802 MyApp[19923:207] *** Terminating app due to uncaught
exception 'NSRangeException', reason:
'*** -[NSMutableIndexSet addIndexesInRange:]:Range {2147483647, 1}
exceeds maximum index value of NSNotFound - 1'

Can anyone help me figure out what is causing the NSRangeException? Here’s my stack:

___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___
obj_exception_throw
+[NSException raise:format:arguments:]
+[NSException raise:format:]
-[NSMutableIndexSet addIndexesInRange:]
-[NSMutableIndexSet addIndex:]
-[_UITableViewUpdateSupport(Private) _computeRowUpdates]
-[_UITableViewUpdateSupport initWithTableView:updateItems:oldRowData:oldRowRange:newRowRange:context:]
-[UITableView(_UITableViewPrivate) _updateWithItems:withOldRowData:oldRowRange:newRowRange:context:]
-[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:]
-[UITableView endUpdates]
-[RootViewController checkBoxTapped:]

If this code is just plain wrong then how should I animate removing a row from one section and adding it to another?

Thanks in advance for any help you can give me.

-Mike-

  • 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-13T12:15:09+00:00Added an answer on May 13, 2026 at 12:15 pm

    Ok, I think I figured out a better approach. Instead of trying to populate the sections using a filtering function I decided to create an array for each section. Each section’s array contains indexes into the data source array. It looks something like this:

    NSArray* data = [[NSArray alloc] initWithObjects:@"Apple", @"Banana", @"Cat", @"Dog", nil]];
    NSMutableArray* doneFilter = [[NSMutableArray alloc] init];
    NSMutableArray* othersFilter = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:0],
                                    [NSNumber numberWithInt:1], [NSNumber numberWithInt:2],
                                    [NSNumber numberWithInt:3], nil];
    

    Now, when the user taps the checkbox I remove the item’s index from the othersFilter and add it to the bottom of the doneFilter. I then remove and add the corresponding rows in the table view. This seems much more stable than what I had before (no exceptions thrown!!) and has the added benefit of allowing the filters to have ordering of their own.

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

Sidebar

Ask A Question

Stats

  • Questions 473k
  • Answers 473k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ok, here for my subjective answer. Standard approach for improving… May 16, 2026 at 3:54 am
  • Editorial Team
    Editorial Team added an answer With NSMutableString you can (and should) just do the following:… May 16, 2026 at 3:54 am
  • Editorial Team
    Editorial Team added an answer You can't create a static unit of work, because by… May 16, 2026 at 3:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.