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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:24:54+00:00 2026-06-17T16:24:54+00:00

I have the following code [self.tV beginUpdates]; NSIndexPath *iP = [NSIndexPath indexPathForRow:indexArray.count inSection:0]; [indexArray

  • 0

I have the following code

[self.tV beginUpdates];
NSIndexPath *iP = [NSIndexPath indexPathForRow:indexArray.count inSection:0];
[indexArray addObject:iP];
[self.tV insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
[self.tV endUpdates];

I get 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 (2) 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 (2 inserted, 0 deleted) and plus or minus the number of rows moved into
or out of that section (0 moved in, 0 moved out).'

I’m not sure where the 2 inserted is coming from. This code is called every time I click a button. The first time there is one element in indexArray, as seen in the code I add one more element but it seems as if it is trying to add both elements again. Is that correct?

UPDATE

-(UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath{

  static NSString *CellIdentifier = @"Cell";

  UITableViewCell *cell = [tableView
                             dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
      cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:CellIdentifier];
  }

  if(_imgList.count>0)
  {
      NSMutableString *fileName = [[NSMutableString alloc]
                                    initWithString:[NSString stringWithFormat: @"img"]];
      [fileName appendString: [_imgList objectAtIndex: _resultTag]];
      UIImage *image = [UIImage imageNamed: fileName];
      UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
      imageView.frame = CGRectMake(_xPos, 0, image.size.width, image.size.height);
      [cell addSubview: imageView];

      _xPos += SPACING;
  }

  return cell;
}


- (IBAction)btn:(UIButton *)sender {
    [self.resultList beginUpdates];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexArray.count inSection:0];
    [indexArray addObject:indexPath];
    [self.resultList insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
[self.resultList endUpdates];

}
  • 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-17T16:24:55+00:00Added an answer on June 17, 2026 at 4:24 pm

    The issue is that you aren’t changing the size of _imgList (from which, I assume, is derived the return value of the tableView:numberOfRowsInSection: method, but you don’t show this method). By inserting a row in the table view, but not updating the data source to reflect that new row, you have created an inconsistency in your application.

    To ensure that this doesn’t happen, make the changes to your data source that reflect exactly the changes you are making to the rows, and do so before inserting or deleting any rows.

    You don’t show code that declares or instantiates _imgList so if it’s not an NSMutableArray you’ll need to make it one, and use methods like addObject:, insertObject:atIndex:, and removeObjectAtIndex: to insert and remove the appropriate objects. In your case, your code would become something like this:

    NSInteger indexToAdd = _imgList.count;
    [_imgList addObject:@"whatever"];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexToAdd 
                                                inSection:0];
    [self.resultList insertRowsAtIndexPaths:@[indexPath]
                           withRowAnimation:UITableViewRowAnimationFade];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: def query(self,query): lock = QMutexLocker(self.mutex) reply = self.conn.query(query) if
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I have the following code: try: redirect_url = self.auth.get_authorization_url() webbrowser.open_new(redirect_url) except tweepy.TweepError: print 'Error!
I have the following code: [[NSNotificationCenter defaultCenter] postNotificationName:kNewsfeedFetchCompleted object:self userInfo:userinfo]; only this, no where
I have the following code: def add_record(self,values): self.sql.execute(INSERT INTO TEST VALUES (?,?) % values)
I have the following code: UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showAddNewView)]; -
I have the following code: def maturities InfoItem.find_all_by_work_order(self.work_order).map(&:maturity) end I was thinking about changing
I have the following code: #!/usr/bin/ruby class Person def self.speak p = self.new puts
Let's say I have the following code: class MyClass(object): def __init__(self, param): self.param =

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.