简体   繁体   中英

how to add the content of the cell of table view in other view when clicked on cell in objective-c

当我单击tableview单元格时,我想在其他视图中添加tableview单元格的内容,如何将单元格的值传递给其他视图。

If you want use the text of a cellview for example you can do that in your UITableViewDelegate (or your UITableViewController):

// Tells the delegate that the specified row is now deselected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     UITableViewCell *targetCell = [tableView cellForRowAtIndexPath:indexPath];
     NSString *contentCell = [targetCell textLabel];

     // Do something with the contentCell
}

In your table view delegate (by default, it's the table view controller) implement the following method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Use indexPath as you did in -tableView:cellForRowAtIndexPath: to get the values you need. To avoid unexpected behavior you should extract the values from your model rather than the cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM