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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:34:01+00:00 2026-06-18T12:34:01+00:00

I am having problems with deleting rows from table view. I am using the

  • 0

I am having problems with deleting rows from table view. I am using the code below when the delete button in the row was pressed:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:control.tag-100 inSection:0];
[resultList removeObjectAtIndex:indexPath.row];
[resultView beginUpdates];
[resultView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[resultView endUpdates];
//[resultView reloadData];

First row was deleted successfully but then, indexes were not correct. So when I delete the last row, it gives index out of bounds exception.

The cell generation code is:

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

    PersonalizeCell *cell = (PersonalizeCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
        cell = [[PersonalizeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];        
    cell.title.text = @"text";
    cell.rateView.tag = indexPath.row + 100;
    return cell;
}

Where am I wrong?

UPDATE:

    for (NSInteger j = 0; j < [venuesTableView numberOfSections]; ++j)
    {
        for (NSInteger i = 0; i < [venuesTableView numberOfRowsInSection:j]; ++i)
        {
           PersonalizeCell* cell = (PersonalizeCell*)[venuesTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]];
           cell.rateView.tag = 100 + i;
        }
    }

solved my problem. Thanks to Nenad M.

  • 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-18T12:34:03+00:00Added an answer on June 18, 2026 at 12:34 pm

    Assuming your [NSIndexPath indexPathForRow:control.tag-100 inSection:0]; returns the right index path….
    Did you try moving the removeObjectAtIndex call inside the begin-/end-updates “bracket”?:

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:control.tag-100 inSection:0];
    [resultView beginUpdates];
    [resultList removeObjectAtIndex:indexPath.row];
    [resultView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    [resultView endUpdates];
    

    UPDATE:

    Obviously your cell.rateView.tag become wrong, after youe delete your first cell.
    So after every deletion (i.e. every removeObjectAtIndex...) you must re-iterate over your remaining tableview-cells an re-assign the proper tag-value (cell.rateView.tag = indexPath.row + 100)! Otherwise your [NSIndexPath indexPathForRow:control.tag-100 inSection:0]; will return a wrong indexPath, therefore leading to your out of bounds error!

    Re-assigning the tag-values:

    You don’t have to reload the entire table, just loop through the remaining cells an re-assign the tag-value after [resultView endUpdates];:

    NSMutableArray *cells = [[NSMutableArray alloc] init];
    for (NSInteger j = 0; j < [tableView numberOfSections]; ++j)
    {
        for (NSInteger i = 0; i < [tableView numberOfRowsInSection:j]; ++i)
        {
            [cells addObject:[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]]];
        }
    }
    

    Now do:

    for (PersonalizeCell* cell in cells)
    {
        cell.rateView.tag = // new calculated tag
    }
    

    (Or do the re-assignment even in the inner-loop of the first code-snippet directly.)


    Here’s some really typical code for the whole process, two lines from the table in the example:

    Note that facebookRowsExpanded is a class variable you must have:

    if ( [theCommand isEqualToString:@"fbexpander"] )
    {
    NSLog(@"expander button......");
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    NSArray *deleteIndexPaths;
    NSArray *insertIndexPaths;
    
    facebookRowsExpanded = !facebookRowsExpanded;
    // you must do that BEFORE, not AFTER the animation:
    
    if ( !facebookRowsExpanded ) // ie, it was just true, is now false
        {
        deleteIndexPaths = [NSArray arrayWithObjects:
                [NSIndexPath indexPathForRow:2 inSection:0],
                [NSIndexPath indexPathForRow:3 inSection:0],
                 nil];
        [tableView beginUpdates];
        [tableView
            deleteRowsAtIndexPaths:deleteIndexPaths
            withRowAnimation: UITableViewRowAnimationMiddle];
        [tableView endUpdates];
        }
    else
        {
        insertIndexPaths = [NSArray arrayWithObjects:
                [NSIndexPath indexPathForRow:2 inSection:0],
                [NSIndexPath indexPathForRow:3 inSection:0],
                 nil];
        [tableView beginUpdates];
        [tableView
            insertRowsAtIndexPaths:insertIndexPaths
            withRowAnimation: UITableViewRowAnimationMiddle];
        [tableView endUpdates];
        }
    
    // DO NOT do this at the end: [_superTableView reloadData];
    return;
    }
    

    NOTE: your code for numberOfRowsInSection must use facebookRowsExpanded

    (it will be something like “if facebookRowsExpanded return 7, else return 5”)

    NOTE: your code for cellForRowAtIndexPath must use facebookRowsExpanded.

    (it has to return the correct row, depending on whether or not you are expanded.)

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

Sidebar

Related Questions

I've a problem deleting a row from a table view. Here is the code
I'm having problems deleting a row using fluent nhibernate. If i execute the below
I am having an odd problem deleting rows from a sqlite database. The first
I am having problems with deleting all records in a table with VB.NET. I
I'm having a problem deleting rows from a datatable. In my program, I am
I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also
I'm having problems deleting a file from a higher directory, I found this post
I'm having an intermittent problem deleting objects from an azure table. It only affects
I'm having a problem with deleting empty directories. Here is my code: for dirpath,
I'm having a hard time figuring out how to prevent Paperclip from deleting the

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.