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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:45:05+00:00 2026-06-10T23:45:05+00:00

I am trying to delete a row in a UITableView which is populated from

  • 0

I am trying to delete a row in a UITableView which is populated from a SQL database.

The sql statement I am using is from a class called databaseHanderClass. The method takes an integer which is the id to delete a row in the database – the primary key.

-(BOOL) deleteFromDatabase: (NSInteger)delete_id
{
   FMDatabase *dbHandler = [FMDatabase databaseWithPath: [Utility getDatabasePath]];
   BOOL success;
   @try 
   {
        [dbHandler open];        
        success = [dbHandler executeUpdate:@"DELETE FROM inputs WHERE id=%d", delete_id];
        [dbHandler close];
   }
   @catch (NSException *exception) 
   {
       NSLog(@"fejl...%@", exception);
   }
   @finally 
   {
       return success;
   }
}

The method I am using for deletion in the UITableView is the following.

- (void)tableView:(UITableView *)tableView commitEditingStyle (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];            

    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) 
    {
         //statement
    }   
}
  • 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-10T23:45:07+00:00Added an answer on June 10, 2026 at 11:45 pm

    You need to implement the following methods: THIS SHOULD WORK

    For your database code, try:

    -(BOOL) deleteFromDatabase: (NSInteger)delete_id
    {
        FMDatabase *dbHandler = [FMDatabase databaseWithPath: [Utility getDatabasePath]];
        BOOL success = NO;
    
        if(![dbHandler open])
        {
            NSLog(@"Could not open DB");
            return NO; 
        }
    
        [dbHandler beginTransaction];
        success = [dbHandler executeUpdate:@"DELETE FROM inputs WHERE id = ?", 
        [NSNumber numberWithInt:delete_id]];
    
        [dbHandler commit]; 
        [dbHandler close];
        return success;
    }
    

    For “commitEditingStyle” method, try the following:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
    {
          if (editingStyle == UITableViewCellEditingStyleDelete) {
          NSInteger row_number_to_be_deleted = indexPath.row;
          //call method to delete from database
          [DatabaseHandler deleteFromDatabase:row_number_to_be_deleted];
    
          //now, fetch all details from Database
          self.dataSource = [DatabaseHandler getAllData];
          [tableView reloadData];
    }
    

    For “NumberOfRowsInSection”:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [self.dataSource count];
    }
    

    For “canEditRowAtIndexPath”:

    -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return YES;
    }
    

    For “editingStyleForRowAtIndexPath”:

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"Editing Style-DELETE %i", [indexPath row]);
        return UITableViewCellEditingStyleDelete;
    }
    

    For “commitEditingStyle”:

     - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
     {
    
         if (editingStyle == UITableViewCellEditingStyleDelete) 
         {
             // Do whatever data deletion you need to do...
             // Delete the row from the data source
             /* This HAS to be changed by YOU */ 
             Employee* emp = [self.dataSource objectAtIndex:[indexPath row]]; 
             NSLog(@"Delete row %i", [indexPath row]);
             [DataEngine removeData:emp];
             [self.dataSource removeObjectAtIndex:[indexPath row]];
         } 
         [self.tableView reloadData];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to simply delete a full row from my SQL Server database table
I am trying to delete a row from UITableview outside the delegate method. I
I am trying to delete a specific row in database. Using the following query:
I'm trying to delete a row from a table in my database from a
I'm trying to delete one row of data from a MySQL database (innodb) in
I am trying to delete a row from a UITableView . My UITableView is
I'm trying to delete the selected row in a gridview from the datatable but
I am trying to delete rows from datagridview, when the user selects any row
I'm trying to create a simple button that deletes a row from the database.
I am trying to delete MySQL table rows from a Web page using Perl.

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.