簡體   English   中英

在objective-c中單擊單元格時如何在其他視圖中添加表視圖單元格的內容

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM