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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:00:09+00:00 2026-05-22T02:00:09+00:00

I have UITableViewController which contains a list of items. Now, I want the list

  • 0

I have UITableViewController which contains a list of items. Now, I want the list to be automatically scrolled to a item (index = bestOne ) once the view appears. Meanwhile I want the item to be colored into red and be labeled as Marked.

My code roughly achieves what I want. But, I actually see more than one red items iterating: every 10 items, there is a red item.

I am quite new to iphone development, I figure it might have something to do with reusable cells. But I am not exactly sure why. Can anybody suggest one way to solve this issue? Thanks in advance.

(void)viewDidAppear:(BOOL)animated
{
    if (self.bestOne != -1)
    {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.bestOne inSection:0];
        [self.tableView scrollToRowAtIndexPath: atScrollPosition: animated:YES];
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [self.array objectAtIndex:indexPath.row];
    if (indexPath.row == self.bestOne)
    {
        cell.detailTextLabel.text = @"Marked";
        cell.textLabel.textColor = [UIColor redColor];
    }
    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-05-22T02:00:09+00:00Added an answer on May 22, 2026 at 2:00 am

    You are right about the reusable cells part.

    Your code should be something like –

    cell.textLabel.text = [self.array objectAtIndex:indexPath.row];
    if (indexPath.row == self.bestOne)
    {
        cell.detailTextLabel.text = @"Marked";
        cell.textLabel.textColor = [UIColor redColor];
    }
    else 
    {
        cell.detailTextLabel.text = @"";
    }
    

    On reuse, you get the exact cell that you had set before. While other cells are undistinguishable, the marked cell stands out with its specifically set detailTextLabel. You need to reset it before you can use it as an unmarked cell.

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

Sidebar

Related Questions

I have a view controller MainVC which contains a view where I want to
I have an edit view in my app which is a instance of UITableViewController
I have a UITableViewController which in it's tableView:didSelectRowAtIndexPath method, sets up a view controller,
I have a UITableViewController in my app, which is added to the view hierarchy
I have presented the viewController which contains a navigation controller whose view is loaded
I have a UITableViewController which contains a UITableView. I try to control the UITableViewController's
I have a view that contains a UITableView and a UILabel which works perfectly
I have a UITableViewController, which is RootViewController. It's XIB only has a table view.
i've UITableViewController which have static cell. I would like to show another detailed view
I have an UITableViewController which I would like to add UIToolbar to with one

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.