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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:06:11+00:00 2026-06-01T10:06:11+00:00

In my app , I am returning 10 user objects in batches using NSNotificationCenter

  • 0

In my app , I am returning 10 user objects in batches using NSNotificationCenter. When I get the 10 objects , I want to insert that data in table view. For this I am using following code

- (void)viewDidAppear:(BOOL)animated {

    recordCounter = 0;
    noOfRowsCounter = 0;

    // Some code
}

- (void) gotNotification: (NSNotification *) notification {

    NSMutableArray *tempArray = [[notification userInfo]valueForKey:KEY];

    NSLog(@"recordCounter BEFORE=> %d",recordCounter);
    NSLog(@"noOfRowsCounter BEFORE=> %d",noOfRowsCounter);

    self.insertIndexPaths = [[NSMutableArray alloc] init]; 
    for (User *user in tempArray) 
    {
        [self.contactsArray addObject:user];

        recordCounter++;
    }

    for (noOfRowsCounter = noOfRowsCounter; noOfRowsCounter < recordCounter; noOfRowsCounter++) {

        [self.insertIndexPaths addObject:[NSIndexPath indexPathForRow:recordCounter inSection:0]];

    }

    NSLog(@"recordCounter AFTER=> %d",recordCounter);
    NSLog(@"noOfRowsCounter AFTER=> %d",noOfRowsCounter);
    NSLog(@"self.insertIndexPaths count=> %d",[self.insertIndexPaths count]);
    [contactsTableView beginUpdates];
    [contactsTableView insertRowsAtIndexPaths:self.insertIndexPaths 
                             withRowAnimation:UITableViewRowAnimationNone];
    [contactsTableView endUpdates];

    [self.insertIndexPaths removeAllObjects];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

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

    // I am doing this as I have 2 records in single row

    if ([self.insertIndexPaths count]%2 == 0) {

        NSLog(@"In IF::rows:: %d",[self.insertIndexPaths count]/2);
        return [self.insertIndexPaths count]/2;
    }
    else {
        NSLog(@"In ELSE::rows:: %d",[self.insertIndexPaths count]/2+1);
        return [self.insertIndexPaths count]/2 + 1;
    }
}

If I run my app I get the following errors & my app crashed. Here is my console log

    2012-04-04 12:15:36.559 AppName[1742:6803] recordCounter BEFORE=> 0
2012-04-04 12:15:36.563 AppName[1742:6803] noOfRowsCounter BEFORE=> 0
2012-04-04 12:15:38.539 AppName[1742:6803] recordCounter AFTER=> 10
2012-04-04 12:15:38.543 AppName[1742:6803] noOfRowsCounter AFTER=> 10
2012-04-04 12:15:38.546 AppName[1742:6803] self.insertIndexPaths count=> 10

2012-04-04 12:15:42.971 AppName[1742:6803] In IF::rows:: 5

2012-04-04 12:15:44.292 AppName[1742:6803] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1448.89/UITableView.m:995
2012-04-04 12:15:44.306 AppName[1742:6803] *** 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 (5) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (10 inserted, 0 deleted).'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x36c4164f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x332fec5d objc_exception_throw + 24
    2   CoreFoundation                      0x36c41491 +[NSException raise:format:arguments:] + 68
    3   Foundation                          0x334ec573 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
    4   UIKit                               0x30ca4379 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 4500
    5   UIKit                               0x30cae2f9 -[UITableView endUpdatesWithContext:] + 28
    6   UIKit                               0x30cae2d5 -[UITableView endUpdates] + 16
    7   AppName                       0x00004927 -[AppNameViewController batchNotification:] + 770
    8   Foundation                          0x334a4183 _nsnote_callback + 142
    9   CoreFoundation                      0x36c1020f __CFXNotificationPost_old + 402
    10  CoreFoundation                      0x36baaeeb _CFXNotificationPostNotification + 118
    11  Foundation                          0x334a15d3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
    12  AppName                       0x00007705 -[AddressBook getAddressBookData] + 1700
    13  AppName                       0x0000447b -[AppNameViewController retriveAddressBookData] + 102
    14  Foundation                          0x334b3389 -[NSThread main] + 44
    15  Foundation                          0x335255cd __NSThread__main__ + 972
    16  libsystem_c.dylib                   0x350c0311 _pthread_start + 248
    17  libsystem_c.dylib                   0x350c1bbc start_wqthread + 0
)
terminate called after throwing an instance of 'NSException'

I want to add those records in table view . How can I do this. Thanks

UPDATE : Code of cellForRowAtIndexPath

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        NSArray *cellArray=[[NSBundle mainBundle] loadNibNamed:@"ContactCell" owner:self options:nil];
        //NSLog(@"cellArray count => %d",[cellArray count]);
        cell=[cellArray objectAtIndex:0];
    }

    // Configure the cell...

    // For showing 2 records in single row

    int row = indexPath.row * 2;
    if (row <= [self.contactsArray count]) 
    {
        User *user = [self.contactsArray objectAtIndex:row];
        NSLog(@"In ROW: %@",user.firstName);
        cell.firstNameLabel.text=[NSString stringWithFormat:@"%@",nameString];
    }

    if ((row + 1) < [self.contactsArray count]) 
    {

        User *user = [self.contactsArray objectAtIndex:row+1];
        NSLog(@"In ROW+1: %@",user.firstName);
        cell.secondNameLabel.text=[NSString stringWithFormat:@"%@",nameString];
    }

     return cell;
}
  • 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-01T10:06:15+00:00Added an answer on June 1, 2026 at 10:06 am

    according to your data you are returning 5 in number of rows in section but your
    self.insertIndexPaths is having 10 index paths

    [contactsTableView insertRowsAtIndexPaths:self.insertIndexPaths 
                             withRowAnimation:UITableViewRowAnimationNone];
    

    these lines specify to insert 10 rows,as mentioned clearly in the error in number of rows you get after updates should equal to the value returned in number of rows in section.

    replace the lines

     for (noOfRowsCounter = noOfRowsCounter; noOfRowsCounter < recordCounter; noOfRowsCounter++) {
    
            [self.insertIndexPaths addObject:[NSIndexPath indexPathForRow:recordCounter inSection:0]];
    
        }
    

    with

        int presentrows = [yourtablename numberOfRowsInSection:0];
        int Finalnumberofrows;
        if ([self.insertIndexPaths count]%2 == 0) {
        Finalnumberofrows = [self.contactsArray count]/2;
    }
    else {
        Finalnumberofrows = [self.contactsArray count]/2 + 1;
    }
        for (presentrows; presentrows < Finalnumberofrows; presentrows++) {
    
        [self.insertIndexPaths addObject:[NSIndexPath indexPathForRow:presentrows inSection:0]];
    
    }
    

    and replace
    table view cell for row at index method
    – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {

    // I am doing this as I have 2 records in single row
    
    if ([self.contactsArray count]%2 == 0) {
    
        NSLog(@"In IF::rows:: %d",[self.insertIndexPaths count]/2);
        return [self.contactsArray count]/2;
    }
    else {
        NSLog(@"In ELSE::rows:: %d",[self.insertIndexPaths count]/2+1);
        return [self.contactsArray count]/2 + 1;
    }
    

    }

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

Sidebar

Related Questions

I inherited a Rails 2.2.2 app that stores user-uploaded images on Amazon S3. The
I'm developing an iOS5 App using ARC, and I started to get some random
I have a WCF service in an ASP.NET AJAX app that is returning json.
I have an app that potentially tracks a large amount of data during app
I've read about some application that reforce app security by deniying all mysql user
I am using Google App engine, in the html file I want to show
In my app I have a background task (using AsyncTask) that downloads stuff from
I am working on an iPad app that is fed data via web service
In my rails app the model is fetching some XML and returning an array.
In writing a django app, I am returning the following json on a jQuery

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.