Believe2014 Believe2014 - 1 year ago 99
iOS Question

How does the `tap` function get ignored?

Following Apple's Guide to build a MealKeeper app, I was able to create a text field and an image view. After dragging and dropping the

on top of the image view, I added the code to hide the keyboard by making the text field to resign.

When I run this code in simulator, I first click on the text field, the keyboard appears.
Then I click on the image view, the keyboard does not get hide.

How does the
function get ignored?

Answer Source

You need to add the gesture to you imageview, create an IBOutlet to your imageview and add the following to 'viewDidLoad'.

let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:Selector("tap:"))
imageView.userInteractionEnabled = true

Good luck.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download