[英]how to get the cell value of a selected cell from Table view in iPhone
在表格视图控制器中显示图像,其中图像以XML文件的形式从URL呈现。 它适合将图像作为滚动视图列出。 现在,我想选择一个特定的图像,并且该窗口应仅显示所选的单元格图像。 为此,我需要获取单元格值。 如果是这样,我如何获取特定的单元格值并在下一个窗口中将其对应的图像显示为集合视图。
请给我一个主意。 为了让您更好地理解,我在图像下方粘贴了我的情节提要当前的外观以及我如何需要输出。
希望你理解我的问题。
-(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将返回段号和所选行的行数。
indexPath.section;
indexPath.row
我希望这很清楚。 为了进一步理解,您可以参考以下教程: http : //www.edumobile.org/iphone/iphone-programming-tutorials/using-iphone-tableview-for-displaying-data/ http://www.raywenderlich.com/ 1797 /如何创建简单的iPhone应用程序教程第1部分
在这种情况下,我认为您应该为该行中的每个图像维护id。 如果每行有一张图像,则可能是您的行号。 然后从
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
您可以将ID传递给下一个视图控制器。 在此视图控制器中,您应该使用此ID来获取创建集合视图所需的数据。 希望这可以帮助。
对我来说,这是工作。
-(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];
}
在目标视图控制器头文件中,只需声明一个字符串,例如
@property NSString *selectedText;
在viewcontroller.m中分配值,例如
self.selectedBiller.text = self.selectedText;
(selectedBiller是此处的标签)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.