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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:36:07+00:00 2026-06-17T04:36:07+00:00

I want to delete a Table View cell, but before that action happens I

  • 0

I want to delete a Table View cell, but before that action happens I want to give the user an alertview. I got this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning"
                                                        message:@"Are you sure?"
                                                       delegate:self
                                              cancelButtonTitle:@"NO"
                                              otherButtonTitles:@"YES", nil];
        [alert show];

        [self.array removeObjectAtIndex:indexPath.row];//or something similar to this based on your data source array structure
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Nee"])
    {
        NSLog(@"Nothing to do here");
    }
    else if([title isEqualToString:@"Ja"])
    {
        NSLog(@"Delete the cell");

    }
}

But now when I swipe to right on the cell and the delete button appears I got no AlertView. I only get the AlertView when I press on the delete button. When I press on the delete button the message appears but the cell is already been deleted.

How to make this work? So there is an AlertView when I swipe.

  • 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-17T04:36:08+00:00Added an answer on June 17, 2026 at 4:36 am

    Regarding the sequence, everything is fine. commitEditingStyle will be called only when the delete button was pressed already. The point is that you are actually removing the object before the alert is responded to. Change it to this:

    Add this to the .m file before @implementation:

    @interface PutYourViewControllerClassNameHere
    @property (strong, nonatomic) NSIndexPath *indexPathToBeDeleted;
    @end
    

    And then:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
    
            self.indexPathToBeDeleted = indexPath;
    
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning"
                                                            message:@"Are you sure?"
                                                           delegate:self
                                                  cancelButtonTitle:@"NO"
                                                  otherButtonTitles:@"YES", nil];
            [alert show];
            // do not delete it here. So far the alter has not even been shown yet. It will not been shown to the user before this current method is finished.     
        }
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        // This method is invoked in response to the user's action. The altert view is about to disappear (or has been disappeard already - I am not sure) 
    
        NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
        if([title isEqualToString:@"NO"])
        {
            NSLog(@"Nothing to do here");
        }
        else if([title isEqualToString:@"YES"])
        {
            NSLog(@"Delete the cell");
    
            [self.array removeObjectAtIndex:[self.indexPathToBeDeleted row]];
            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPathToBeDeleted] withRowAnimation:UITableViewRowAnimationFade];
        }
    }
    

    Edit: This should compile, despite minor syntax errors probably.
    General assupmtion: You are dealing with one section only. At least only with one section within deletions are possible.

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

Sidebar

Related Questions

I want to modify my table view cell apparence when the delete button came
I want to have a delete user link in a normal Activerecord table, but
I want to create a JSF table like this . But instead delete button
I have a table view that I want to delete some of the cells
Currently, I have a table view that the user can add items and delete
I want to perform different action, not delete objects but archive them. When user
When deleting a row in a table view, I want to show an action
I have a table that currently lets you swipe to delete. I want to
I have a simple grouped table view that when a cell is selected it
I want to delete a cell in one of my 2 tableViews (1 is

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.