如何从iPhone中的表视图中获取所选单元格的单元格值

时间:2022-04-13 09:44:10

Am displaying images in a table view controller where the images are rendered from the URL as XML file. It works well with listing images as scroll view. Now i want to select a particular image and the window should show the selected Cell images alone. For this do i need to get the Cell value. If so how can i get the particular cell value and display its corresponding images as a collection view in next window.

我在图表视图控制器中显示图像,其中图像从URL呈现为XML文件。它适用于将图像列为滚动视图。现在我想选择一个特定的图像,窗口应该单独显示所选的单元格图像。为此,我需要获得Cell值。如果是这样,我如何获得特定的单元格值并在下一个窗口中将其对应的图像显示为集合视图。

Kindly suggest me an idea. For your better understanding i pasted below an image how my storyboard currently looks and how i need an output. 如何从iPhone中的表视图中获取所选单元格的单元格值

请建议我一个想法。为了更好地理解我在图像下方粘贴了我的故事板当前的外观以及我需要输出的方式。

Hope you understand my problem.

希望你能理解我的问题。

4 个解决方案

#1


22  

-(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.
}

#2


2  

You should use UITableViewDelegate

你应该使用UITableViewDelegate

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

indexPath will return you number of section and number of row of selected row.

indexPath将返回所选行的节数和行数。

indexPath.section;
indexPath.row

I hope it was clear. For further understanding you may refer to following tutorials: http://www.edumobile.org/iphone/iphone-programming-tutorials/using-iphone-tableview-for-displaying-data/ http://www.raywenderlich.com/1797/how-to-create-a-simple-iphone-app-tutorial-part-1

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

#3


1  

In this case I think you should maintain id for each image on the row. It could be your row number, if you have one image per row. Then from

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

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

you can pass the id to the next view controller. In this view controller you should use this id to get the required data to create your collection view. Hope this helps.

您可以将id传递给下一个视图控制器。在此视图控制器中,您应使用此id来获取创建集合视图所需的数据。希望这可以帮助。

#4


0  

For me this is working..

对我来说,这是有效的..

-(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]; 
}

And in your destination view controller header file just declare a string like

在目标视图中,控制器头文件只是声明一个字符串

@property NSString *selectedText;

In viewcontroller.m assign the value like

在viewcontroller.m中赋值如

self.selectedBiller.text = self.selectedText;

(selectedBiller is a label here)

(selectedBiller是这里的标签)

#1


22  

-(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.
}

#2


2  

You should use UITableViewDelegate

你应该使用UITableViewDelegate

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

indexPath will return you number of section and number of row of selected row.

indexPath将返回所选行的节数和行数。

indexPath.section;
indexPath.row

I hope it was clear. For further understanding you may refer to following tutorials: http://www.edumobile.org/iphone/iphone-programming-tutorials/using-iphone-tableview-for-displaying-data/ http://www.raywenderlich.com/1797/how-to-create-a-simple-iphone-app-tutorial-part-1

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

#3


1  

In this case I think you should maintain id for each image on the row. It could be your row number, if you have one image per row. Then from

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

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

you can pass the id to the next view controller. In this view controller you should use this id to get the required data to create your collection view. Hope this helps.

您可以将id传递给下一个视图控制器。在此视图控制器中,您应使用此id来获取创建集合视图所需的数据。希望这可以帮助。

#4


0  

For me this is working..

对我来说,这是有效的..

-(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]; 
}

And in your destination view controller header file just declare a string like

在目标视图中,控制器头文件只是声明一个字符串

@property NSString *selectedText;

In viewcontroller.m assign the value like

在viewcontroller.m中赋值如

self.selectedBiller.text = self.selectedText;

(selectedBiller is a label here)

(selectedBiller是这里的标签)