views:

96

answers:

2

Hi guys,

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.

A: 

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
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
A: 

Hi Guys,

I solved it by using this code:

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

Thanks for the suggestions.

StefanHanotin