开发者

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

I want to add the content of the cell of tableview in othe开发者_StackOverflow社区r view when i click on the tableview cell , how can i pass the values of the cell to other view.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜