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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:41:14+00:00 2026-06-14T17:41:14+00:00

I use cellForRowAtIndexPath like here: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString

  • 0

I use cellForRowAtIndexPath like here:

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil)
        cell = [self getCellContentView:CellIdentifier];


    UILabel *lbl = (UILabel*)[cell.contentView viewWithTag:1];

    for (UITableViewCell *c in [tbl visibleCells])
    {
     //   UITableViewCell *cell2 = [tbl cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        UILabel *lbl = (UILabel*)[c.contentView viewWithTag:1];
        lbl.textColor = [UIColor redColor];
    }

    if([tbl indexPathForCell:cell].section==0)
        lbl.textColor = [UIColor whiteColor];


    UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
    UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];

    //First get the dictionary object

    lblTemp1.text =  @"test!";
    lblTemp2.text = @"testing more";

    NSLog(@"%@",[tbl indexPathForCell:cell]);

    return cell;


}

But is still makes some of my cells white instead of gray.

How can I change only the first item in the row to white?

  • 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-14T17:41:15+00:00Added an answer on June 14, 2026 at 5:41 pm

    First: ditch the

    for (UITableViewCell *c in [tbl visibleCells])
    {
        //UITableViewCell *cell2 = [tbl cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        UILabel *lbl = (UILabel*)[c.contentView viewWithTag:1];
        lbl.textColor = [UIColor redColor];
    }
    

    and change it to

    UILabel *lbl = (UILabel*)[c.contentView viewWithTag:1];
    lbl.textColor = [UIColor redColor];
    

    no need to go trough all the visible cells here.

    Then change

    if([tbl indexPathForCell:cell].section==0)
            lbl.textColor = [UIColor whiteColor];
    

    to

    if((indexPath.section==0)&&(indexPath.row==0))
            lbl.textColor = [UIColor whiteColor];
    

    If this class/object is delegate of several tableViews you should
    add additional checking for

    if ((tableView == correctTableView)&&...
    

    It’s worth to notice that

    [tbl indexPathForCell:cell]
    

    is irelevant. Your reference is parameter (NSIndexPath *)indexPath.

    If problems persist you should post the code of your getCellContentView: method.

    EDIT: according to rmaddy’s advice and since cellForRowAtIndexPath: is important performance-vise it would be better to use:

    if((indexPath.section==0)&&(indexPath.row==0))
    {
        lbl.textColor = [UIColor whiteColor];
    }
    else
    {
        lbl.textColor = [UIColor redColor];
    }
    

    This way you avoid unnecessary double change when dealing with first cell.

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

Sidebar

Related Questions

in method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath usually you use an array to
Here is my code below: - (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row
I use this code UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; NSString *cellText = cell.textLabel.text; in
when i use this code it shows an error - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
I would like, given the indexPath, to get a reference to the related cell
I am experimenting in tableView:cellForRowAtIndexPath to set an image by calling [self downloadImage:urlString andSetIntoCellImageView:cell]
iam developing one application.In that i place the imageview in every tableview cell like
In my application in tableview cell for row at index method I use the
I'm trying to add as subview into a section in UITableView, It looks like
Hey everybody, I'm very confused about how to use two different Cell Types in

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.