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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:25:54+00:00 2026-05-16T10:25:54+00:00

I have a UITableView with 2 sections. The section 0 contains a list of

  • 0

I have a UITableView with 2 sections. The section 0 contains a list of file names and the user can tap them to toggle the checkmark accessory. This section is also editable so the user can swipe to delete a file/row. The section 1 is not editable and contains 1 row and acts as a button to initiate a transfer of the files.

Thus, the datasource for the table looks like this:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

switch (section) {
    case SECTION_FILES:
        return [files count];
        break;
    case SECTION_ACTIONS:
        if ([files count]) {
            return 1;       // ROW_ACTIONS_TRANSFER
        return 0;
        break;
}
return 0;

}

The behavior that I want is for section 1 to display only when section 0 has rows. The problem I’m finding is that when the last row in section 0 is removed section 1 still contains 1 row. To remove the row from section 1 I figured I should either call deleteRowsAtIndexPath or reloadSections while committing the edit for the last row in section 0 and then the cell would be animated out. However, doing this causes my app to crash saying:

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).’

I can call reloadData on the tableview, but the update is a drastic redraw and I would much prefer to animate the cells out. Is there a way to accomplish what I want? I feel like this should be easy and I’m missing something obvious.

My commitEditingStyle code is below. I delete from my datasource (files) first, that is the recommended way, right?

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        switch ([indexPath section]) {
            case SECTION_FILES:
                [files removeObjectAtIndex:indexPath.row];
                [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
                // Here is where I would call [tableView reloadData] or [tableView reloadSection...
                break;
        }

}
}

  • 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-16T10:25:55+00:00Added an answer on May 16, 2026 at 10:25 am

    I was able to solve this on my own, but not in as elegant a way as I wanted. Essentially, what I do is keep a member variable to track whether or not I have inserted SECTION_ACTIONS into the tableview. Then when SECTION_FILES is modified I do:

    [tableview beginUpdates];
    [tableview insertSection SECTION_ACTIONS];
    self.showingActionsSection = YES;
    [tableview endUpdates];
    

    or

    [tableview beginUpdates];
    [tableview deleteSection SECTION_ACTIONS];
    self.showingActionsSection = NO;
    [tableview endUpdates];
    

    Luckily, doing it like this allows me to get nice smooth animations as things are added and removed. However, it makes UITableView datasource behave a little differently than I am used to.

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

Sidebar

Related Questions

I have a need to display a UITableView containing a user's account credentials. For
I have an array of objects which populate a UITableView . When a user
In an app I'm working on, I have a plain style UITableView that can
I have a UITableView cell that is going to have a variable size depending
I have got an UITableView. How to simply fill it with three elements, for
I have a UIView with a UITableView for a subview. The UIView has an
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I

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.