how to check the number of clicks the user clicks on an image in swift - swift

Is there a function to count the numbers of click that the user clicks on an image and when the user starts clicking on another image the count resets.
Like for example : there is an image that requires the user to click on it for 3 times , then another image comes out that requires the user to click on it for 5 times , is there a function that can help me in the touchBegan method.

You can use a UITapGestureRecognizer and add one to all the image views you need. As selector you can choose the same method for every gesture recognizer. When the user press in the method you increase the counter and save the view that has received the tap, if the user change the view you can find a mismatch between the previous view and the pressed one. In this case you reset the couter.

Related

How can I tell which button was pressed LAST - SWIFT?

Pretty basic - I have multiple buttons and I just need to tell which button was pressed most recently, despite how many times on each or how long between clicks.
Give each button a unique tag in Interface Builder.
Make a variable that holds the tag of the last button that has been clicked.
In event handlers of your buttons set the variable from the step above to the tag of the button currently being clicked.
When you need to find the last button that has been clicked, check the variable, it will have the unique tag of your button.

Display a message when cursor over on UILabel

How can I display some text message when a label is tapped?
I have a label (Address).Now and when I tap over on it, I need to display the corresponding address in a small popup.
How can I do it?
I found out from your comment that you actually want to have a pop up on tap event.
All you need to do is
Have a button on the UILabel (on which you want to show pop up).
Make button of cutom type (It will make the button disappeared).
After that write a method to show pop up, and connect it to that custom button.
For creating a pop up, you can use UIView of desired size and position & make it appear/disappear on custom button tap event (touch up inside).
Hope this helps.

Adding a button to last UITableView row

I'm developing an app where the user can choose between a number of included songs. I also want the user to be able to choose a song from his/her iPod Library.
Currently the song is choosen by selecting it in a UITableView. So I figure I would like to add a new row at the end of the table and make it a button that will fire a MPMediaPickerController. All songs are placed in an array consisting of their names.
My question is how I add this last row? And also how I can "save" the selected song (or the path to it) to be used in the parent viewcontroller?
Well, you can use the UITableViewCell directly as a button itself, so when a user clicks on the last row, the action is being executed. But if I understand you right, you want to add a specific extra button as a subview of a UITableViewCell. That means if the cell (the last row) is being built, you compose your button, add its target and action, and add the button just as simple subview of the cell.
Well, the parent should now receive the message that the button has been pushed. I would do this using NSNotification, that is very easy to use, just check out the Apple documentation and take a look at an example. You can even send the selected song or its name path via the notification directly to the parent controller, where you can handle this notification.

UIPickerView - Selects row too fast

I am currently using a UIPIckerView in my app to allow a user to select from a list of options. The problem is that there isn't enough of a delay when the user stops spinning the wheel and it is selecting a value before the user has a chance to scroll further down the list.
Is there a way to override the default behavior that selects the row as soon as the wheel stops spinning and the user removes their finger? I see Mobile Safari includes a "Done" button which would be great.
I can provide code if necessary (not sure how it would help).
Thanks!
You can add this manually; just add a done button to the view that holds the UIPicker, and have IT do whatever action you're currently performing in – pickerView:didSelectRow:inComponent:.
The UIPickerView automatically selects which ever row stops in the center. It does not work like a table but more like a popup menu. As such, you can't use a picker view like a button to call an action because it will trigger the moment the user stops moving it whether that represents their final choice or not.
Instead, as noted previously, you need a second control element (usually a button) to call the action that makes use of the pickerview's selection.

Display an image on screen after button is pressed in Cocoa

I was wondering what I should use to display an image on screen every time the user presses a button. I am using Objective-C/CocoaTouch on the iPod Touch. I would like to pull these images from an array I have set up and place them on the screen when the button is triggered. I feel dumb asking but any one that can point me in the right direction would be great. I think I could figure out the rest from there.
Thanks.
I'm sure there are many ways of doing this, but one way would be to define a UIImageView on the screen, and make it hidden. When the user presses the button, you can set the source of the UIImageView to the image from your array, and set the hidden property to NO.
I think it's as simple as something like this:
[myImageView setImage:[imageArray objectAtIndex:theIndex]];
In your button's action method. You can set theIndex before or afterwards to get a different image from your array every time the action method gets called.