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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:03:04+00:00 2026-06-05T03:03:04+00:00

I´m quite new to iOS development and I´m having a terrible time by trying

  • 0

I´m quite new to iOS development and I´m having a terrible time by trying something that should be easy; to add an extra row in a TableView everytime the user clicks on one of the existing rows. There is no real purpose on that action, I´m just wanting to understand the behaviour of TableView.

So I did the following:

I used a Split View-based template and changed the number of rows to 30 in the RootViewController.

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
   // Return the number of rows in the section.
   return 30;
}

The method tableView:didSelectRowAtIndexPath looks in the following manner:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    /*
    When a row is selected, set the detail view controller's detail item to the item associated with the selected row.
    */
   NSMutableArray* paths = [[NSMutableArray alloc] init];
   NSIndexPath *indice = [NSIndexPath indexPathForRow:30 inSection:0];
   [paths addObject:indice];
   detailViewController.detailItem = [NSString stringWithFormat:@"Second Story Element %d with all its information and bla bla bla", indexPath.row];
   [[self tableView] beginUpdates];
   [self.tableView insertRowsAtIndexPaths:(NSArray *) paths withRowAnimation:UITableViewRowAnimationNone];
   [[self tableView] endUpdates];
}

When I execute the program and click on one of the elements, I receive the following error:

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

I did not change any other part of the code that the template provides.

I read quite extensively the documentation from Apple and the responses to the following questions:
Add a row dynamically in TableView of iphone
and
how to properly use insertRowsAtIndexPaths?

The second question seems to address the same problem, but I´m not capable to understand what is happening. What do they mean with dataSource? The response that I understand better says the following:

It’s a two step process:
First update your data source so numberOfRowsInSection and cellForRowAtIndexPath will return the correct values for your post-insert data. You must do this before you insert or delete rows or you will see the “invalid number of rows” error that you’re getting.

What does this update of the data source implies?

Sample code would be HIGHLY appreciated, because I´m totally frustrated.

By the way, all that I´m trying has nothing to do with entering the editing mode, has it?

  • 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-05T03:03:05+00:00Added an answer on June 5, 2026 at 3:03 am

    You need to keep the count returned by tableView:numberOfRowsInSection: in sync!

    So when you have 30 rows and then tell the tableview to insert a new row you need to make sure tableView:numberOfRowsInSection: will now return 31.

    - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
    {
       return self.rowCount;
    }
    
    - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
       self.rowCount++;
    
       [self.tableView beginUpdates];
       [self.tableView insertRowsAtIndexPaths:(NSArray *) paths withRowAnimation:UITableViewRowAnimationNone];
       [self.tableView endUpdates];
    }
    

    In practice you would probably use an array to track your rows return [self.rows count]; etc

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

Sidebar

Related Questions

I am quite new to iOS development and trying hard to develop an App.
I am quite new to iOS development and just thought to take guidance from
I am quite new to IOS development, so forgive me if this problem turns
I'm new to IOS development, and want to create something with tiles similar to
I'm new to Objective C (iOS) and I'm having a hard time figuring out
I'm relatively new to iOS development and I have a question that I'm sure
I'm quite new here. I have a problem with the new iOS 5.1 slide-in
Quite new to maven here so let me explain first what I am trying
I'm quite new to OpenId and I'm having a bit of a problem understanding
So I'm new to iOS development and am doing all I can to learn

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.