如何从iPhone的Table视图中获取选定单元格的单元格值

我在表格视图控制器中显示图像,其中的图像是从URL作为XML文件呈现的。 它可以很好地将图像列为滚动视图。 现在我想select一个特定的图像,窗口应该单独显示选定的单元格图像。 为此,我需要获取单元格值。 如果是这样,我怎么能得到特定的单元格的值,并显示其相应的图像作为收集视图在下一个窗口。

请告诉我一个想法。 为了更好的理解,我在图片下方粘贴了我的故事板目前的外观以及我需要的输出。 故事板和输出

希望你了解我的问题。

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // here we get the cell from the selected row. UITableViewCell *selectedCell=[tableView cellForRowAtIndexPath:indexPath]; // perform required operation UIImage * image =selectedCell.image; // use the image in the next window using view controller instance of that view. } 

你应该使用UITableViewDelegate

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

indexPath将返回你所select行的行数和行数。

 indexPath.section; indexPath.row 

我希望这是清楚的。 为了进一步理解你可以参考以下教程: http : //www.edumobile.org/iphone/iphone-programming-tutorials/using-iphone-tableview-for-displaying-data/ http://www.raywenderlich.com/ 1797 /如何到创build-A-简单与iPhone应用教程-部分- 1

在这种情况下,我认为你应该维护行上的每个图像的ID。 这可能是你的行号,如果你每行有一个图像。 然后从

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

您可以将该ID传递给下一个视图控制器。 在这个视图控制器,你应该使用这个ID来获取所需的数据来创build您的collections视图。 希望这可以帮助。

对我来说这是工作..

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; customerVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"customerInfoView"]; customerVC.selectedText = cell.textLabel.text; //customerVC is destination viewController instance) [self.navigationController pushViewController:customerVC animated:YES]; } 

并在你的目的地视图控制器头文件只是声明一个string

 @property NSString *selectedText; 

在viewcontroller.m中赋值如

 self.selectedBiller.text = self.selectedText; 

(selectedBiller是这里的标签)