单击objective-c中的单元格时,如何在其他视图中添加表视图单元格的内容

时间:2010-02-15 07:36:28

标签: iphone objective-c

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

2 个答案:

答案 0 :(得分:1)

如果你想使用cellview的文本,你可以在你的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
}

答案 1 :(得分:0)

在表视图中委托(默认情况下,它是表视图控制器)实现以下方法:

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

像在-tableView中一样使用indexPath:cellForRowAtIndexPath:获取所需的值。为避免意外行为,您应该从模型而不是单元格中提取值。