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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:17:49+00:00 2026-05-30T07:17:49+00:00

I have a BarButton Item and the name of it is Edit when it

  • 0

I have a BarButton Item and the name of it is Edit when it is in edit mode, and Done when it is done with editing. So when the user clicks on edit the editpress method gets executed (see code).

With that the, commitEditingStyle , and the cell and the record (from the array which is used to add data to the cell) is deleted.

The problem : When i click on delete, the cell gets deleted from the table correctly. But not from the array which is used to load the cells. When i placed a debug point at commitEditingStyle, it only executes that code when i FIRST click on delete. If i delete records for the 2nd, 3rd etc this code block is not executed. Why is this ?

I have not added [self.tableView setEditing:YES animated:YES]; record in commitEditingStyle. Is that the flaw.

note: i don’t think my delete from array logic is incorrect, because the same logic works in other programs (gurantted, and that’s why i didnt post it)

  -(void) editpress:(id)sender{
        UIBarButtonItem *editButton = (UIBarButtonItem*)self.navigationItem.leftBarButtonItem;    
        if (!self.tableView.editing) {  
            [self.tableView setEditing:YES animated:YES];
            UIButton *rbut= [UIButton buttonWithType:UIButtonTypeCustom];
            [rbut setImage:rightImage forState:UIControlStateNormal];       
            [rbut addTarget:self action:@selector(editpress:) forControlEvents:UIControlEventTouchUpInside];        
            UIBarButtonItem *rBarButDone =  [[UIBarButtonItem alloc] initWithCustomView:rbut];
            self.navigationItem.rightBarButtonItem = rBarButDone;       
        }
        else { 
            [self.tableView setEditing:NO animated:YES];
            UIButton *rbut= [UIButton buttonWithType:UIButtonTypeCustom];
            [rbut setImage:rightImage forState:UIControlStateNormal];              
            [rbut addTarget:self action:@selector(editpress:) forControlEvents:UIControlEventTouchUpInside];        
            UIBarButtonItem *rBarButEdit =  [[UIBarButtonItem alloc] initWithCustomView:rbut];
            self.navigationItem.rightBarButtonItem = rBarButEdit;
        }
    }


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {        
        [self.tableView beginUpdates];
        // I write the logic to delete the record from the array and the table here.         
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]  withRowAnimation:YES];  
        [self.tableView endUpdates];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
  • 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-30T07:17:51+00:00Added an answer on May 30, 2026 at 7:17 am

    The code is obviously executing the commitEditingStyle. However, after you delete, does the cellForRowAtIndexPath now return the correct data for the row that was deleted? If you’re reading that data from an internal array that you downloaded, then you need to delete an item from that internal array. If you’re reading from another source, you need to either make sure that source is sending the correct data, or you’re refreshing it after deleting the row. In either case, whatever your “web service” is doing to delete the data is not refreshing the cell with new data. Also, you’ll need to report one fewer in numberOfRowsInSection: method.

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

Sidebar

Related Questions

Have done quite a bit of searching for a guide (of any substance) for
I have a Bar Button Item in one of my screens. The button should
I have a custom bar button item that I want to nudge down 5
Am working in an iPhone app using UITableView . I have added the editing
I have a navigation controller. I want to add a right bar button item
i have added a UIPopover to my navigationbar when the user touches the rightbarbuttonitem.
I have used FrameLayout within a Gallery as the Gallery Item. There are 2
I have added a bar button item in my tool bar and I implemented
I have searched around an figured out how to add a UISegmentedControl item to
I am loading a mapview. I have created a barbutton in the bottombar toolbar

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.