Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In this line of code:</p> <pre><code>NSString *anotherString = cell.textLabel.text; </code></pre> <p>How are you obtaining the cell? Is it nil? Also, the <em>textLabel</em> field you're accessing is the default label in the a UITableViewCell and not the label you are adding in <em>-cellForRowAtIndexPath</em>. Here is how you can get the cell from <em>-didSelectRowAtIndexPath</em>:</p> <pre><code>- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self tableView:tv cellForRowAtIndexPath:indexPath]; } </code></pre> <p>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:</p> <pre><code>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]; </code></pre> <p>So, now you can access the UILabel by tag:</p> <pre><code>- (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]); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload