[英]how to add the content of the cell of table view in other view when clicked on cell in objective-c
当我单击tableview单元格时,我想在其他视图中添加tableview单元格的内容,如何将单元格的值传递给其他视图。
例如,如果要使用单元格视图的文本,则可以在UITableViewDelegate(或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
}
在您的表视图委托(默认情况下,它是表视图控制器)中,实现以下方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
像在-tableView:cellForRowAtIndexPath:中一样使用indexPath来获取所需的值。 为避免意外行为,您应该从模型而不是单元中提取值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.