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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:53:24+00:00 2026-05-11T18:53:24+00:00

I have an UITableView with sections in my iPhone application where it looks as

  • 0

I have an UITableView with sections in my iPhone application where it looks as something similar to viewing a contact details in standard contacts app. In one of the sections I have a UISegmentedControl set as a header of the section and the items in that section depend on what segment is selected in the segmented control. What I wanted to do is to have animations shifting the rows of one tab out of the view to one side and shifting the rows of another tab in from the other side. I have managed to achieve this by inserting/deleting the respective rows with default UITableView’s animations for that but it looks a bit weird when the number of rows in one tab is different from the other one. Also the code for that is quite nasty.

Here’s the code I have (simplified a bit):

[self.tableView beginUpdates];
UITableViewRowAnimation delAnim = UITableViewRowAnimationRight;
UITableViewRowAnimation insAnim = UITableViewRowAnimationLeft;
NSUInteger numdel = [self.list count];
NSUInteger numins = [newlist count];
NSMutableArray* indices = [NSMutableArray arrayWithCapacity: numdel];
for (NSUInteger i = 0; i < numins; i++)
{
    [indices addObject: [NSIndexPath indexPathForRow: i  inSection: SECT]];
}
[self.tableView insertRowsAtIndexPaths: indices  withRowAnimation: insAnim];
[indices removeAllObjects];
for (NSUInteger i = 0; i < numdel; i++)
{
    [indices addObject: [NSIndexPath indexPathForRow: i  inSection: SECT]];
}
[self.tableView deleteRowsAtIndexPaths: indices  withRowAnimation: delAnim];
self.list = newlist;
[self.tableView endUpdates];

I’m fairly new to Objective C and Cocoa, so any advices are very welcome.

  • 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-11T18:53:24+00:00Added an answer on May 11, 2026 at 6:53 pm

    You could try using a separate table view which you animate in directly. The snippet here is just typed off-the-cuff, so might need some work, but it should give you some pointers at least:

    - (void) switchToNewTableFromRight
    {
        UITableView * newTableView = [[UITableView alloc] initWithFrame: self.tableView.frame style: self.tableView.style];
    
        // put it off to the right of the existing table
        CGRect frame = newTableView.frame;
        frame.origin.x += frame.size.width;
        newTableView.frame = frame;
    
        // set data for new table
        // you should ensure you're setup to supply data for the new table here, btw
        newTableView.delegate = self;
        newTableView.dataSource = self;
        [newTableView reloadData];
    
        // add to parent of current table view at this (offscreen) location
        [self.tableView.superview addSubview: newTableView];
    
        // now we animate
        [UIView beginAnimations: @"TableFromRight" context: newTableView];
    
        // set the function it should call when the animation completes
        [UIView setAnimationDelegate: self];
        [UIView setAnimationDidStopSelector: @selector(animation:finished:context:)];
    
        // set new table's frame to current table's frame
        newTableView.frame = self.tableView.frame;
    
        // set current table's frame to be offscreen to the left
        frame = self.tableView.frame;
        frame.origin.x -= frame.size.width;
        self.tableView.frame = frame;
    
        // commit the animations to start them going
        [UIView commitAnimations];
    }
    
    - (void) animation: (NSString *) animationID finished: (BOOL) finished context: (void *) context
    {
        // could be a good idea to check that finished == YES here
        UITableView * newTableView = (UITableView *) context;
        self.tableView = newTableView;
    
        // newTableView has been inited but not autoreleased, etc.
        // now the controller (self) owns it, so release that first reference
        [newTableView release];
    }
    

    The idea here is that you setup the new table (making it the same size as the existing one), place it offscreen to the right of the existing table, and then animate the movement of both tables left by their width. This way the existing table will shift offscreen while the new one will shift onscreen. When the animation completes it will call the supplied method, giving you the opportunity to make the new table view the official table view.

    Another option would be to use a flip transition, which might go something like this:

    // setup new table
    UITableView * newTableView = [[UITableView alloc] initWithFrame: self.tableView.frame style: self.tableView.style];
    newTableView.delegate = self;
    newTableView.dataSource = self;
    [newTableView reloadData];
    
    [UIView beginAnimations: nil context: NULL];
    [UIView setAnimationDuration: 1.0];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView: self.tableView.superview cache: YES];
    
    // generally here you'd remove the old view and add the new view
    // I'm *assuming* that UITableViewController's -setTableView: will do the same thing
    self.tableView = newTableView;
    
    [UIView commitAnimations];
    

    Hopefully one of those will have the desired effect.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

So I'm making a very basic Twitter app (it's actually Presence 2 from the
I have an UITableView, and in it I have different sections - words that
I'm using Matt Gallagher's GenericTableViewController idea for controlling my UITableViews . My datasource is
In an app I'm working on, I have a plain style UITableView that can

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.