jeudi 30 juin 2016

How to get the selected index path for UIImageView object present on a UITableVIewCell of UITableView?

I have a tableview with custom tableView cell present in it. I have placed a UIImageview on custom tableViewCell. When i press or touch the imageView, i want to download some images from url, on the basis of selected index, which i am going to pass it(selectedIndex) as a string in the url.

What happens is when i first touch the image view, i am not getting the selected index path. But when i first select the cell and then i press the image view, at that time i get the selected index path. I searched it on the internet, but didn't found any appropriate solution. Here below is my code where i assign a UILongPressRecognizer to the UIImageView, in cellForRowAtIndexPath method.

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


cell.imgvDownload.tag=indexPath.row;
    singleTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected12)];

    [cell.imgvDownload setUserInteractionEnabled:YES];
    [singleTap.delegate self];
    [singleTap setMinimumPressDuration:0.01f];
    [cell.imgvDownload addGestureRecognizer:singleTap];

return cell;
}

The problem is that UIImageview is to able to get the selected index path for the row selected. But if i first select any cell(row) from tableView and then press the UIImage view, i get the index. Can anyone please tell me what wrong am i doing here. Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire