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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:43:18+00:00 2026-06-13T03:43:18+00:00

i got a UITableViewCell which i want to stay selected when clicked on it.

  • 0

i got a UITableViewCell which i want to stay selected when clicked on it. So i have this code which works just fine:

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

static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%@", [[[self.dataSource objectAtIndex:indexPath.row] lastPathComponent] stringByDeletingPathExtension]];
    //cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView *bgColorView = [[UIView alloc] init];
    [bgColorView setBackgroundColor:[UIColor brownColor]];
    [cell setSelectedBackgroundView:bgColorView];
    return cell;
}

Everytime i click on a cell it gets selected with the brown color and stays selected until i click another cell… perfect
But when i dismiss the view by clicking on the back button of my navigationcontroller and then i switch back to my view my cell is not selected anymore. So how can i achieve that the cell which was selected before i switched the views still is selected when i come back to the view ?

I thought i maybe have to create a property from the tableview and then select the row in the viewDidLoad again. The selectedRow index i could save in the nsuserdefaults.. but i hope there is a simpler solution.

  • 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-13T03:43:20+00:00Added an answer on June 13, 2026 at 3:43 am

    In your -viewDidLoad method, add this to the bottom: self.clearsSelectionOnViewWillAppear = NO; Which would make it look something like this:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        self.clearsSelectionOnViewWillAppear = NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used the following code: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString
I have got an history page, which is a UItableview with 5 rows. I
I have a custom UITableViewCell. However, when I got in edit mode, I don't
I've got a custom UITableViewCell subview that has a button on it which has
I got UITableView in simple view, which controlled by UIViewController I implement methods like
I've got the following code which should put an image in the top section/cell
In my UIView nib file, I've got a UITableView which takes up about half
I got app with UITableView. There is UILabel in each UITableViewCell. I add labels
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath I think if the table is empty, namely that
I have a uipickerview which i want to populate with data from my sqlite

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.