开发者

Custom UITableViewCell with 3 labels

开发者 https://www.devze.com 2023-01-08 06:06 出处:网络
I have a custom UITableViewCell and in it I have 2 labels. The 2 labels in the custom cell have name and location.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消