简体   繁体   English

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

[英]how to get the cell value of a selected cell from Table view in iPhone

Am displaying images in a table view controller where the images are rendered from the URL as XML file. 在表格视图控制器中显示图像,其中图像以XML文件的形式从URL呈现。 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. 如果是这样,我如何获取特定的单元格值并在下一个窗口中将其对应的图像显示为集合视图。

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. 为了让您更好地理解,我在图像下方粘贴了我的情节提要当前的外观以及我如何需要输出。 故事板和输出

Hope you understand my problem. 希望你理解我的问题。

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

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 /如何创建简单的iPhone应用程序教程第1部分

In this case I think you should maintain id for each image on the row. 在这种情况下,我认为您应该为该行中的每个图像维护id。 It could be your row number, if you have one image per row. 如果每行有一张图像,则可能是您的行号。 Then from 然后从

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

you can pass the id to the next view controller. 您可以将ID传递给下一个视图控制器。 In this view controller you should use this id to get the required data to create your collection view. 在此视图控制器中,您应该使用此ID来获取创建集合视图所需的数据。 Hope this helps. 希望这可以帮助。

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是此处的标签)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM