I have a custom complex UITableViewCell where there are many views. I have an UIImageView within it which is visible for a specific condition. When it's visible ,
I have to perform some Action when user Taps that UIImageView.
I know I have to trigger a selector for this task. But I also want to pass a value to that Method (please See -(void)onTapContactAdd :(id) sender : (NSString*) uid below) that will be called as a Action of Tap on my UIImageView in UITableViewCell I am talking about. It's because , using that passed value , the called method will do it's job.
Here is what I have tried so far.
cell.AddContactImage.hidden = NO ;
cell.imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapContactAdd::)];
[tap setNumberOfTouchesRequired:1];
[tap setNumberOfTapsRequired:1];
[tap setDelegate:self];
[cell.AddContactImage addGestureRecognizer:tap];
-(void)onTapContactAdd :(id) sender : (NSString*) uid
{
NSLog(@"Tapped");
// Do something with uid from parameter
}
This method is not called when I tap. I have added in my header file.
Thanks for your help in advance.
you can use ALActionBlocks to add gesture to UIImageView and handle action in block
Install
A gesture recognizer will only pass one argument into an action selector: itself. So u need to pass the uid value alone.Like this.
Guessing this lies within the cellForRowAtIndexPath: method
So here when you tap on the visible image in the respective custom cell,the onTapContactAdd: method gets called with the corresponding uid value(parameter) and now we have the cell.AddContactImage also accessible which i believe is why you were trying to pass it also along with the parameters . Hope it Helps!!!
Maybe not the ideal solution, but add tags to each of the UIImageViews. Then have an NSArray with the uid's corresponding to the tag values
So somewhere in your code make the array
Then when you're setting up the tableview cells set the tag to the row #
Then in the method that gets called you can get the tag like this
Add the gesture recognizer to the cell itself.
Then in the action selector, do as following to know which view has been tapped:
Another one, with the
indexPath
, if it's ok for you to handle the tap in DataSource:You may want to make the code shorter if you have only one
tableView
.Here, We have customtableviewcell both .h and .m files with two images in cell. And HomeController, which have tableview to access this cell. This is detect the Tap on both the UIImage as described.