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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:12:27+00:00 2026-05-25T12:12:27+00:00

So I want to be able to determine how to differentiate insert operations from

  • 0

So I want to be able to determine how to differentiate insert operations from delete operations so that I can respond accordingly. Currently I have this code to create a “Done”, “Edit” and “Add” button

- (void)initializeNavigationBarButtons
{
    UIBarButtonItem *newEditButton = 
    [[UIBarButtonItem alloc]
     initWithBarButtonSystemItem:UIBarButtonSystemItemEdit 
     target:self action:@selector(performEdit:)];

    self.editButton = newEditButton;
    [newEditButton release];

    self.navigationItem.rightBarButtonItem = self.editButton;

    UIBarButtonItem *newDoneButton = 
    [[UIBarButtonItem alloc]
     initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
     target:self action:@selector(performDone:)];

    self.doneButton = newDoneButton;
    [newDoneButton release];

    UIBarButtonItem *newAddButton = 
    [[UIBarButtonItem alloc]
     initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
     target:self action:@selector(performAdd:)];

    self.addButton = newAddButton;
    [newAddButton release];
    self.navigationItem.leftBarButtonItem = self.addButton;

}

then I have these 3 as the so-called “callback” functions for the buttons:

- (void)performDone:(id)paramSender
{
    [self.tableView setEditing:NO animated:YES];


    [self.navigationItem setRightBarButtonItem:self.editButton
                                      animated:YES];

    [self.navigationItem setLeftBarButtonItem:self.addButton
                                      animated:YES];
}

- (void)performEdit:(id)paramSender
{
    NSLog(@"Callback Called");
    [self.tableView setEditing:YES animated:YES];

    [self.navigationItem setRightBarButtonItem:self.doneButton
                                      animated:YES];

    [self.navigationItem setLeftBarButtonItem:self.doneButton
                                     animated:YES];
}

- (void)performAdd:(id)paramSender
{
    [self.tableView setEditing:YES animated:YES];

    [self.navigationItem setRightBarButtonItem:self.doneButton
                                      animated:YES];

    [self.navigationItem setLeftBarButtonItem:self.doneButton
                                      animated:YES];
}

and here is where I am “supposed to” determine whether it is an add or delete operation:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *output = (isDeleting) ? @"Deleting" : @"Adding";

    NSLog(@"%@", output);

    UITableViewCellEditingStyle result = UITableViewCellEditingStyleNone;

    if ([tableView isEqual:self.tableView]){
        if (self.isDeleting == YES){
            result = UITableViewCellEditingStyleDelete;
        }
        else{
            result = UITableViewCellEditingStyleInsert;
        }
    }

    return result;
}

however, I don’t know where I am supposed to set self.isDeleting and self.isAdding. I tried to set them in the callbacks but it seems that the tableView:cellEditingStyleForRowAtIndexPath: gets called first and in my viewDidLoad the default value for them is NO.

So how do I properly set the values of isAdding and isDeleting for me to be able to act accordingly in the tableView:cellEditingStyleForRowAtIndexPath: method?

Thanks in advance!

  • 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-25T12:12:28+00:00Added an answer on May 25, 2026 at 12:12 pm

    If you have an ‘Add’ button in the navigation bar why not just run the ‘add’ action when it’s pressed instead of making the tableview editable? There’s also not much point in setting a cell’s editing style to UITableViewCellEditingStyleInsert when that cell has content. The usual flow is to either have an ‘Add’ button outside the table (e.g: in the navigation bar) which performs the add action, or as the last (or first) cell inside the tableview while it’s in editing style, and when that cell is pressed the add action is performed.

    So you can either keep the ‘Add’ button in the navigation bar and make all cells editable with UITableViewCellEditingStyleDelete, or keep only the ‘Edit’/’Done’ buttons and while editing add a new cell (while the tableview is editable) which will be editable with UITableViewCellEditingStyleInsert.

    Side note: instead of if ([tableView isEqual:self.tableView]) you should better use if (tableView == self.tableView) since you want to check if it’s the same instance, and not if they’re equal.

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

Sidebar

Related Questions

I have an application that uses a barcode scanner. I want to be able
I want to be able to determine if the number of bytes in an
I want to be able to determine if the html contents of a particular
I want to be able to pass something into an SQL query to determine
I want to be able to capture the exception that is thrown when a
I want to be able to determine whether a particular domain controller is read-only.
I currently have a form with about 13 buttons on it. I want to
I have a string that I want to display on a web page that
I want to be able to determine the output folder based on the platform
I want to be able to determine if a browser supports HSL colours, if

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.