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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:57:34+00:00 2026-06-07T23:57:34+00:00

I’ve created a UITableview with sections that are clickable. When you click on them,

  • 0

I’ve created a UITableview with sections that are clickable. When you click on them,

  1. they “expand” to reveal cells within them
  2. the clicked section scrolls to the top of the view.

I calculate all of the indexpaths to insert/delete the necessary cells and then insert them with the following code:

[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:pathsToOpen withRowAnimation:insertAnimation];
[self.tableView deleteRowsAtIndexPaths:pathsToClose withRowAnimation:deleteAnimation];
[self.tableView endUpdates];
[self.tableView scrollToRowAtIndexPath:[pathsToOpen objectAtIndex:0]  atScrollPosition:UITableViewScrollPositionTop animated:YES];

There’s only one problem- the sections below the selected section are hidden. The first screen-shot shows how the tableview should look. The second screen-shot shows how it actually looks.

Sections Disappear

If you scroll up (so the hidden sections are offscreen) and then scroll back down, the hidden sections are brought back (once again visible). My guess as to why this is happening is the following:

The insert/delete animations are happening at the same time as the scrollToRowAtIndexPath and it is confusing the TableView. If I hadn’t done scrollToRowAtIndexPath sections 3 & 4 would have been offscreen – and so the tableView somehow still thinks they are offscreen. UITableview hides cells/sections that are offscreen as an optimization. If I call scrollToRowAtIndexPath with a dispatch_after with 2 seconds, then sections 3 & 4 are displayed correctly.

So I think I know why this is happening, but I don’t know how to fix/override this UITableview optimization. Actually, if I implement scrollViewDidEndScrollingAnimation and then add a breakpoint in this function, the app displays sections 3 & 4 correctly (that’s how I got the first screen-shot). But once continuing from this function, the cells disappear.

The full project can be downloaded here


Additional implementation details: Sections are legitimate UITableView sections. I’ve added a tapGestureRecognizer that triggers a delegate callback to the tableview. Included below is the entire method that opens the sections.

- (void)sectionHeaderView:(SectionHeaderView *)sectionHeaderView sectionOpened:(NSInteger)sectionOpened
{
    // Open
    sectionHeaderView.numRows = DefaultNumRows;
    sectionHeaderView.selected = YES;
    NSMutableArray *pathsToOpen = [[NSMutableArray alloc] init];
    for (int i = 0; i < sectionHeaderView.numRows; i++)
    {
        NSIndexPath *pathToOpen = [NSIndexPath indexPathForRow:i inSection:sectionOpened];
        [pathsToOpen addObject:pathToOpen];
    }

    // Close
    NSMutableArray *pathsToClose = [[NSMutableArray alloc] init];
    if (openSectionHeader)
    {
        for (int i = 0; i < openSectionHeader.numRows; i++)
        {
            NSIndexPath *pathToClose = [NSIndexPath indexPathForRow:i inSection:openSectionHeader.section];
            [pathsToClose addObject:pathToClose];
        }
    }

    // Set Correct Animation if section's already open
    UITableViewRowAnimation insertAnimation = UITableViewRowAnimationBottom;
    UITableViewRowAnimation deleteAnimation = UITableViewRowAnimationTop;
    if (!openSectionHeader || sectionOpened < openSectionHeader.section)
    {
        insertAnimation = UITableViewRowAnimationTop;
        deleteAnimation = UITableViewRowAnimationBottom;
    }

    openSectionHeader.numRows = 0;
    openSectionHeader.selected = NO;
    openSectionHeader = sectionHeaderView;


    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:pathsToOpen withRowAnimation:insertAnimation];
    [self.tableView deleteRowsAtIndexPaths:pathsToClose withRowAnimation:deleteAnimation];
    [self.tableView endUpdates];
    [self.tableView scrollToRowAtIndexPath:[pathsToOpen objectAtIndex:0]  atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
  • 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-06-07T23:57:36+00:00Added an answer on June 7, 2026 at 11:57 pm

    From what I can tell, the problem is occurring when returning a section view that’s already been used. Instead of:

    - (UIView *)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
    {
        return [self.sectionHeaderViews objectAtIndex:section];
    }
    

    I get no problem if I create a new view each time:

    - (UIView *)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section{
        SectionHeaderView *sectionHeaderView = [self.tableView dequeueReusableCellWithIdentifier:SectionHeaderView_NibName];
        sectionHeaderView.textLabel.text = [NSString stringWithFormat:@"Section %d", section];
    
        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:sectionHeaderView action:@selector(handleTap:)];
        [sectionHeaderView addGestureRecognizer:tapRecognizer];
        sectionHeaderView.section = section;
        sectionHeaderView.delegate = self;
        return sectionHeaderView;
    }
    

    It’s possible this is occurring because you’re using [self.tableView dequeueReusableCellWithIdentifier:SectionHeaderView_NibName]; to create section headers and hold on to them in an array, which I don’t think UITableViewCell was created for, but I’m not certain. You may want to consider foregoing UITableViewCell for section views and instead use something else (perhaps a UIImageView with a UILabel). Or you can just not store the Section Views in an array…the way you currently have your code set up, you don’t need the array and creating a new view is trivial enough you don’t need to worry about it.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
i want to parse a xhtml file and display in UITableView. what is the
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

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.