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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:52:52+00:00 2026-06-16T11:52:52+00:00

I have gesture recognisers set up on my table view. Swipe to the right

  • 0

I have gesture recognisers set up on my table view.

  • Swipe to the right and the accessory changes to an image of a tick
  • Swipe to the left and is changes to a chevron image

If a cell is tapped, it loads a local HTML file.

If you swipe to the right, the tick appears as it should. However, if you then tap a cell to view a HTML file and come back to the table view, the image reverts to the chevron.

What’s the best way to ensure the tick stays as it should?


EDIT

Further code:

From ‘viewDidLoad’:

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                                 action:@selector(handleSwipeRight:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.tableView addGestureRecognizer:recognizer];

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                       action:@selector(handleSwipeLeft:)];
//recognizer.delegate = self;
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.tableView addGestureRecognizer:recognizer];


- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer
{
//Get location of the swipe
CGPoint location = [gestureRecognizer locationInView:self.tableView];

//Get the corresponding index path within the table view
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];

//Check if index path is valid
if(indexPath)
{
    //Get the cell out of the table view
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    //Update the cell or model

    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disclosure.png"]];
}
}

- (void)handleSwipeRight:(UISwipeGestureRecognizer *)gestureRecognizer
{
CGPoint location = [gestureRecognizer locationInView:self.tableView];

NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];

if(indexPath)
{
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    // cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tick.png"]];
}

}

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

static NSString *simpleTableIdentifier = @"MFGCell";

MFGCell *cell = (MFGCell *) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MFGCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

cell.itemTitle.text = [item objectAtIndex:indexPath.row];
cell.itemDescription.text = [description objectAtIndex:indexPath.row];
cell.itemImageView.image = [UIImage imageNamed:[icons objectAtIndex:indexPath.row]];

return cell;
}
  • 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-16T11:52:53+00:00Added an answer on June 16, 2026 at 11:52 am

    In reaction to the user’s swipe you should store the user’s choice (e.g. in a private instance variable of type NSMutableArray). When the user comes back to the table view you can then reuse the information in your tableView:cellForRowAtIndexPath: to setup the cell with the correct accessory style.

    Property declaration:

    @property(nonatomic, retain) NSMutableArray* _accessoryStyle;
    

    Synthesize the property. Then add this snippet to the bottom of handleSwipeLeft: to store the user’s choice:

    - (void)handleSwipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer
    {
      [...]
      NSNumber* number = [numberWithInt:0];
      [_accessoryStyle replaceObjectAtIndex:indexPath.row withObject:number];
    }
    

    Add a similar snippet to the bottom of handleSwipeRight::

    - (void)handleSwipeRight:(UISwipeGestureRecognizer *)gestureRecognizer
    {
      [...]
      NSNumber* number = [numberWithInt:1];
      [_accessoryStyle replaceObjectAtIndex:indexPath.row withObject:number];
    }
    

    In tableView:cellForRowAtIndexPath::

    NSString* accessoryImageName;
    NSNumber* number = [_accessoryStyle objectAtIndex:indexPath.row];
    switch ([number intValue])
    {
      case 0:
        accessoryImageName = @"disclosure.png";
        break;
      case 1:
        accessoryImageName = @"tick.png";
        break;
      default:
        // replace with your error handling code
        return nil;
    }
    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:accessoryImageName]];
    

    For all this to work you need to initialize the _accessoryStyle array with the same number of elements that you expect your table view to have cells. For instance, in your view controller’s viewDidLoad:

    - (void) viewDidLoad
    {
      [super viewDidLoad];
    
      self._accessoryStyle = [NSMutableArray arrayWithCapacity:0];
      NSNumber* defaultAccessoryStyle = [numberWithInt:0];
      int numberOfRows = 17;  // get the real number from somewhere
      for (int index = 0; index < numberOfCells; ++index)
        [_accessoryStyle addObject:defaultAccessoryStyle];
    }
    

    And to balance this you need to add

    - (void) viewDidUnload
    {
      [super viewDidUnload];
      self._accessoryStyle = nil;
    }
    

    There is still much room for improvement:

    • Find better variable names
    • Use an enumeration for the different styles instead of just hardcoded numbers 0 and 1
    • Do not allocate a new UIImageView for each table view cell, just allocate two of them and use the right one depending on the accessory style
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added two swipe gesture recognizers (swipe left and swipe right) to my
I have set up a gesture recognizer for my table cell in my IOS5
I have an UIImageView which can be rotated, panned and scaled with gesture recognisers.
I have a simple swipe gesture that I want to be very low priority.
I have a custom control/view that observes the direction of a gesture within its
I have attached 3 tap gesture recognizers to the same view - single, double
I have an endlessly looping CABasicAnimation of a repeating image tile in my view:
I have set up some gesture recognition in an app that I'm building. One
I have an app that I'd like the swipe gesture to flip to a
In my app I need have a swipe gesture recogniser on my background scroller

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.