-1

Working with swift. got a tableView with a custom Cell. have the imageView in cell and trying work out why the tap/touch function with uiimageview doesn't work. In my cellForRowAtIndexPath

var tap = UITapGestureRecognizer(target: self, action: "handleTap:") -

cell.smallImageView.tag = (indexPath.row)

cell.smallImageView.addGestureRecognizer(tap)

and a function called "handleTap"

I have the userinteraction enabled. Also have didSelectRowIndexPath and that is being used for some (segue).

Am i missing something? I have been stalking through stackoverflow and couldn't find a solution.

Thanks in advanced!

Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57
user2800022
  • 65
  • 1
  • 9
  • 2
    Assuming your method is `func handleTap(sender: UITapGestureRecognizer)`. Did you set userinteraction enabled on the cell or on the ImageView? And where are you setting it (in cellForRowAtIndexPath?)? – mad_manny Dec 07 '15 at 10:20
  • I think the cell takes the tap gesture and calls `didSelectRowForIndexPath` instead of calling `handleTap`. – NSNoob Dec 07 '15 at 10:29
  • @NSNoob: I did use both `didSelectRowForIndexPath` and setting a recognizer on a UI element inside the cell for several times and it always worked. So I don't think this is the problem here. – mad_manny Dec 07 '15 at 10:31
  • try setting userInteractionEnabled = true progrmatically – michal.ciurus Dec 07 '15 at 14:05
  • @NSNoob I did try with commeting out whole didSelectrowForIndexPath and i see no actions when build and run. – user2800022 Dec 07 '15 at 19:28
  • @michal.ciurus i can try that, although i did have have them enabled both from story board and programatically. was trying everything :( – user2800022 Dec 07 '15 at 19:31
  • @mad_manny I did have userinteraction enabled on the imageView from the checkbox of the main storyboard. and yes i did have those settings in cellForRowAtIndexPath. should i have userinteraction enabled also in cell as well? – user2800022 Dec 07 '15 at 19:41
  • Commenting didSelectRow delegate does not stop your cell from taking the tap event. It will still get touched even though it will not perform any action as the method does not exist – NSNoob Dec 08 '15 at 05:10
  • 1
    @NSNoob Ok, So how should i proceed? should i remove all out or any short idea i can do a quick try? Thanks~ – user2800022 Dec 08 '15 at 05:50
  • Thank you guys, i got it working. adding an asnwer below – user2800022 Dec 08 '15 at 06:00

1 Answers1

1

Found solution after struggling and learning quite a lot from reading through stackoverflow.com (thank you stackover)

Basically, I got an idea from mad_manny, mentioned something about having userinteraction on/off form cell. i got idea and had look into "Content View" from storyboard and i don't know if it's default or somehow unticked, so i ticked the box and now its working fine. one tick wasted my 3days of time but it's ok. learned a lot again! no pain no gain i guess!

Thanks to all @mad_manny, @NSNoob

user2800022
  • 65
  • 1
  • 9