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

人盡茶涼 提交于 2019-12-03 13:43:24
Vinayak Kini
-(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.
}
Aditya Mathur

You should use UITableViewDelegate

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

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

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

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

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

Narasimha Nallamsetty

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

self.selectedBiller.text = self.selectedText;

(selectedBiller is a label here)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!