tom
tom

Reputation: 14513

how to tell which image of a set was tapped on in a UITableViewCell

For one of my tableview, there are images in some of cells and there could be more than one images in each of those cells. Now when user tapped on an image, I want to bring up a image viewer to show the full image. But I have a hard time to figure out the best way to know which picture was tapped on. I created them as UIImageView. Any suggestions?

Upvotes: 0

Views: 150

Answers (5)

Gaurav_soni
Gaurav_soni

Reputation: 6114

You can use tags as suggested in the other answers or you can use switch case

in the method -

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

switch(indexPath.section) {

    case 0:{
//set the _imagename = @"Something"
break;
}
    case 1:{
//set the _imagename = @"Something else"
break;
}
}

hope this helps

Upvotes: 0

Rohit Wankhede
Rohit Wankhede

Reputation: 506

Set tag for each images of cell.

In .h declare

 NSInteger TagValue ;

In .m ViewDidLoad

 TagValue = 0;

At CellForRowAtIndexPath :

TagValue++;

image1.tag = TagValue;

TagValue++;

image2.tag = TagValue;

On selection of it , now you have tag value on that you can get particular selected image.

And to get images form array

image1.image = [array objectAtIndex:image1.tag]; 

you will get your respective image.

Upvotes: 3

Anand
Anand

Reputation: 1129

what you can do is , instead of using UIImageView , use Costume Button and set the Image of That costume button and give all the buttons different tags... each cell will have set of buttons with different tags and by assigning the single selector to all button you can easily determine that which image is clicked.

or

Upvotes: 0

Raj Subbiah
Raj Subbiah

Reputation: 1292

Set tag for imageview and you can easily find out the tapped image

Upvotes: 2

Piyush Kashyap
Piyush Kashyap

Reputation: 1965

set the tag of each image of a particular cell and then you can access those images through their tags

Upvotes: 0

Related Questions