1

I have a custom UITableViewCell and in it I have 2 labels. The 2 labels in the custom cell have name and location.

What I need to be able to do is, select a row and use the text in the name label of the row as the title for the next viewController.

Any ideas on how I could do this?

Thanks.

StefanHanotin
  • 191
  • 5
  • 17
  • It depends on how you are drawing the cell. Did you create a NIB based cell or are you using `drawRect` to draw one? – iwasrobbed Jul 22 '10 at 20:40

2 Answers2

0

Give the label in the cell a tag, like kMyNameLabelTag, when the cell is created. When the cell is selected, use cellForRowAtIndexPath to get the cell then viewWithTag to get the label in the cell.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *theName = [(UILabel *)[[[tableView cellForRowAtIndexPath:indexPath] contentView] viewWithTag:kMyNameLabelTag] text];
}

This assumes you added the labels to the contentView.

drawnonward
  • 53,459
  • 16
  • 107
  • 112
  • In addition to the above response, you may find some useful information for communicating between view controllers here: http://stackoverflow.com/questions/569940/whats-the-best-way-to-communicate-between-view-controllers/575497#575497 – iwasrobbed Jul 22 '10 at 22:26
0

I solved it by using this code:

anotherViewController.navigationItem.title= [NSString stringWithFormat:@"%@%@", @"Patient No: ", patient.ID];

Thanks for the suggestions.

StefanHanotin
  • 191
  • 5
  • 17