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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:02:17+00:00 2026-06-13T20:02:17+00:00

I am trying to make this work but can’t seem to wrap my mind

  • 0

I am trying to make this work but can’t seem to wrap my mind around the idea.

So far I have it to where you are able to select a cell and it be able to produce a checkmark. Then, when you select a different cell, the previous checkmark would go away and the tableview would make a new checkmark on the new cell you just selected. This all works beautifully.

However, I am wanting to make it to where when you select the same cell with the checkmark,
the checkmark does not disappear. But, it does!

I have tried numerous amounts of if statements to see if I can figure out how to make this work but can’t figure out a solution. It is probably something minor that I need to rearrange in my code.

Here is my code:

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

    if(self.checkedIndexPath)
    {
        UITableViewCell* uncheckCell = [tableView
                                        cellForRowAtIndexPath:self.checkedIndexPath];
        uncheckCell.accessoryType = UITableViewCellAccessoryNone;
        [tableView deselectRowAtIndexPath:indexPath animated:YES];

    }

    if([self.checkedIndexPath isEqual:indexPath])
    {
        self.checkedIndexPath = nil;
    }

    else
    {
         cellCheck = [tableView cellForRowAtIndexPath:indexPath];
        cellCheck.accessoryType = UITableViewCellAccessoryCheckmark;
        self.checkedIndexPath = indexPath;
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        NSLog(@"%@", indexPath);

    }
}
  • 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-13T20:02:19+00:00Added an answer on June 13, 2026 at 8:02 pm

    If you select the cell with checkmark, this code will be executed.

    if(self.checkedIndexPath)
    {
        UITableViewCell* uncheckCell = [tableView
                                         cellForRowAtIndexPath:self.checkedIndexPath];
         uncheckCell.accessoryType = UITableViewCellAccessoryNone;
         [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    

    This code will remove the checkmark which you have added during the first select.

    then this code will be executed

    if([self.checkedIndexPath isEqual:indexPath])
    {
        self.checkedIndexPath = nil;
    }
    

    Thus only when you select the same cell again, the checkmark will reappear

    I think the cleaner way will be as followed.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell* cellCheck = [tableView
                                        cellForRowAtIndexPath:indexPath];
        cellCheck.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    
    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell* uncheckCell = [tableView
                                        cellForRowAtIndexPath:indexPath];
        uncheckCell.accessoryType = UITableViewCellAccessoryNone;
     }
    

    AS you can get the value for self.checkedIndexPath from [tableView indexPathForSelectedRow]; the setting of self.checkedIndexPath is optional depending on the logic of your code.

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

Sidebar

Related Questions

I am trying to make this IF statement work, but I can't seem to
I am trying very hard to make this work but I can't see what
I have been pulling my hair out trying to make this work. I have
ive browsed many articles here but I just can't make this work for the
I'm having headaches trying to make this work: I have a <a> element with
I am trying to make this ajax request function work but netbeans is giving
I'm trying to make this centred wrapper work fluidly with the viewport, but im
I'm trying to make the following work but can't figure out how to combine
I have been trying to make this work for a long time now. In
I am trying to make this query work but i keep getting error. insert

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.