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.开发者_JAVA百科
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.
I solved it by using this code:
anotherViewController.navigationItem.title= [NSString stringWithFormat:@"%@%@", @"Patient No: ", patient.ID];
Thanks for the suggestions.
精彩评论