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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:00:22+00:00 2026-06-10T02:00:22+00:00

I have a tableView where I select cells and add the data in an

  • 0

I have a tableView where I select cells and add the data in an array, I also have the option of swiping and then deleting a particular cell which eventually deletes the data from the array.

The problem is that once I delete a row, I lose all my selection state after I reload the table,

For that I checked again with the selection array and reselected all these cells,

BUT I am stuck at one place, Much before I actually delete a cell and reload the tableView, as soon as I swipe over a cell, selection state of all other cells also go away.

NOTE: I have two arrays, one with list of itmes to be displayed in the tableView and one with the selected items.

Here is some code:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;  
}


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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *MyIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    }

    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    [cell.textLabel setTextColor:[UIColor colorWithRed:103.0/255.0 green:103.0/255.0 blue:103.0/255.0 alpha:1.0]];
    [cell.textLabel setFont:[UIFont fontWithName:@"ITCAvantGardeStd-Bk" size:14.0]];

    if (![[[self.contactList objectAtIndex:indexPath.row] objectForKey:@"nickName"] isEqualToString:@""])
        cell.textLabel.text = [NSString stringWithFormat:@"%@",[[self.contactList objectAtIndex:indexPath.row] objectForKey:@"nickName"]];

    else
        cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",[[self.contactList objectAtIndex:indexPath.row] objectForKey:@"firstName"],[[self.contactList objectAtIndex:indexPath.row] objectForKey:@"lastName"]];

    return cell;


}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{

    NSLog(@"Selected cell index==>%d\n",indexPath.row);
    //NSString *emailID = [NSString stringWithFormat:@"%@",[[self.contactList objectAtIndex:indexPath.row] objectForKey:@"email_key"]];
    NSLog(@"emailID==>%@\n",[self.contactList objectAtIndex:indexPath.row]);    
    [self.emailShareList addObject:[self.contactList objectAtIndex:indexPath.row]];
    //[self.emailShareList insertObject:emailID atIndex:indexPath.row];
    NSLog(@"Array value==>%@\n",self.emailShareList);
    //[tableView deselectRowAtIndexPath:indexPath animated:YES];
}


- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"deSelected cell index==>%d\n",indexPath.row);
    NSString *emailID = [NSString stringWithFormat:@"%@",[[self.contactList objectAtIndex:indexPath.row] objectForKey:@"email_key"]];
    NSLog(@"emailID==>%@\n",emailID);   

    [self.emailShareList removeObject:[self.contactList objectAtIndex:indexPath.row]];
    NSLog(@"deSelect row Array value==>%@\n",self.emailShareList);
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        if(indexPath.row != 0)
        {
            NSString *contactID = [[self.contactList objectAtIndex:indexPath.row] objectForKey:@"contactId"];
            NSLog(@"content on delete row==>%@\n",contactID);
            [self.contactList removeObjectAtIndex:indexPath.row];
            [self deleteContactToServer:contactID];
        }
    }

    [contactTableView reloadData];
    for (int i = 0; i < [self.emailShareList count]; i++) 
    {
        for (int j = 0; j < [self.contactList count]; j++) 
        {
            if([[[self.contactList objectAtIndex:j] valueForKey:@"email"]   isEqualToString:         [[self.emailShareList objectAtIndex:i] valueForKey:@"email"]])
            {
                NSIndexPath *path1 = [NSIndexPath indexPathForRow:j inSection:0];
                [contactTableView selectRowAtIndexPath:path1 animated:NO scrollPosition:UITableViewScrollPositionNone];
            }
        }    
    }
}


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{




    UITableViewCellEditingStyle style = UITableViewCellEditingStyleNone;

    if(indexPath.row != 0)
        style = UITableViewCellEditingStyleDelete;


    return style;
}
  • 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-10T02:00:24+00:00Added an answer on June 10, 2026 at 2:00 am

    When you delete an item, you don’t necessary have to reload the entire tableview. You could use the – deleteRowsAtIndexPaths:withRowAnimation: method to just remove the cell in question (along with an according model update). This will probably retain your selection.

    To keep your selections when entering editing mode (swipe for delete is a special case of editing mode as well) you nee to do two things:

    First, enable allowsSelectionDuringEditing on your tableView:

    self.tableView.allowsSelectionDuringEditing = YES;
    

    Second, create a UITableView subclass and override setEditing:animated: like this:

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
        NSArray *indexPaths = self.indexPathsForSelectedRows;
        [super setEditing:editing animated:animated];
        for (NSIndexPath *ip in indexPaths) {
            [self selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionNone];
        }
    }
    

    Personally, I would rather use some sort of custom selection mechanism, when selections are important from a model point of view. I would create a custom cell subclass, add a selection property to it let it change the cell styling accordingly. The build-in features that affect regular table view selections won’t cause problems with such an approach.

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

Sidebar

Related Questions

I have 5 cells in my tableview. User can select a row which sets
I have a tableview and when I select one cell I am changing the
I have used the following code to programmatically select tableview cells - (void) selectTableCell{
I have a table view it displays data which we select time using the
I have a tableview and an array source. When I init array in viewDidLoad
i have a tableView with 3 cells. i want to change .detailTextLabel of that
I have a UITableView on a view. This UITableView has cells which are made
I have a tableview, where when the user selects the cell it will set
I am trying to add margin to a cell. I have tried many times
I have tableview with some names on each cell , how can i get

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.