Access custom label property at didSelectRowAtIndexPath.

Posted by Mr. McPepperNuts on Stack Overflow See other posts from Stack Overflow or by Mr. McPepperNuts
Published on 2010-06-16T15:43:32Z Indexed on 2010/06/16 15:52 UTC
Read the original article Hit count: 322

Filed under:
|

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;

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c