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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:40:03+00:00 2026-05-15T08:40:03+00:00

I have a UILabel for each cell at cellForRowAtIndexPath. UILabel *cellLabel = [[UILabel alloc]

  • 0

I have a UILabel for each cell at cellForRowAtIndexPath.

UILabel *cellLabel = [[UILabel alloc] initWithFrame:frame];
cellLabel.text = myString;

I want to access that string “myString” at didSelectRowAtIndexPath using indexpath.

NSString *anotherString = cell.textLabel.text;

returns null.

Now if at cellForRowAtIndexPath, I did something like cell.textLabel.text = theString; then the didSelectRowAtIndexPath returns the appropriate cell.

My question is, how can I access the text in the UILabel I apply to the cell, at didSelectRowAtIndexPath?

Also, logging the cell in didSelectRowAtIndexPath returns cell: <UITableViewCell: 0x5dcb9d0; frame = (0 44; 320 44); autoresize = W; layer = <CALayer: 0x5dbe670>>

Edit:

    NSString *myString = [[results objectAtIndex:indexPath.row] valueForKey:@"name"];
//cell.textLabel.text = myString;

CGFloat width = [UIScreen mainScreen].bounds.size.width - 50;
CGFloat height = 20;
CGRect frame = CGRectMake(10.0f, 10.0f, width, height);

UILabel *cellLabel = [[UILabel alloc] initWithFrame:frame];
cellLabel.text = myString;
cellLabel.textColor = [UIColor blackColor];
cellLabel.backgroundColor = [UIColor whiteColor];
cellLabel.textAlignment = UITextAlignmentLeft;
cellLabel.font = [UIFont systemFontOfSize:14.0f];
[cell.contentView addSubview:cellLabel];
[cellLabel release];

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-15T08:40:04+00:00Added an answer on May 15, 2026 at 8:40 am

    In this line of code:

    NSString *anotherString = cell.textLabel.text;
    

    How are you obtaining the cell? Is it nil? Also, the textLabel field you’re accessing is the default label in the a UITableViewCell and not the label you are adding in -cellForRowAtIndexPath. Here is how you can get the cell from -didSelectRowAtIndexPath:

    - (void)tableView:(UITableView *)tv 
                     didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [self tableView:tv cellForRowAtIndexPath:indexPath];
    
    }
    

    The issue at this point, though, is that you can’t access the UILabel by name, however, you can access it if you’ve set a tag. So, when you create your UILabel, set the tag like this:

    UILabel *cellLabel = [[UILabel alloc] initWithFrame:frame];
    cellLabel.text = myString;
    cellLabel.textColor = [UIColor blackColor];
    cellLabel.backgroundColor = [UIColor whiteColor];
    cellLabel.textAlignment = UITextAlignmentLeft;
    cellLabel.font = [UIFont systemFontOfSize:14.0f];
    
    // Set the tag to any integer you want
    cellLabel.tag = 100;
    
    [cell.contentView addSubview:cellLabel];
    [cellLabel release];
    

    So, now you can access the UILabel by tag:

    - (void)tableView:(UITableView *)tv 
              didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [self tableView:tv cellForRowAtIndexPath:indexPath];
    
        UILabel *label = (UILabel*)[cell viewWithTag:100];
    
        NSLog(@"Label Text: %@", [label text]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UILabel with right-aligned text that may vary from between three to
I have a UILabel: descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 30, 130, 150)]; [descriptionLabel setFont:[Utils
I have a list that uses UILabel for each of its rows. If I
I have a UITableView with each cell containing the following 1) A UILabel (listing
I have a UITableView that has about 20 cells. Each has a UILabel within,
I have a UITableView made of static cells, and each cell contains a UILabel
i have a html string that's like: [div][p]some text here[/p][img src=@url][b] here's image[/b][/div] How
I have three UILabel with different font and I want to put then on
I have a UILabel with space for two lines of text. Sometimes, when the
I have a UILabel that displays some chars. Like x, y or rpm. How

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.