Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-18-2011, 07:41 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 70
juanchofern is on a distinguished road
Thumbs up Detect touch of uiimageview

Hello I would like to do an array of uiimageviews and when i touch an uiimageview i would like to know which uiimageview has been touched.
I would like to get the index.

Does anybody how to do it?

Thanks in advance!!
juanchofern is offline   Reply With Quote
Old 08-18-2011, 07:55 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by juanchofern View Post
Hello I would like to do an array of uiimageviews and when i touch an uiimageview i would like to know which uiimageview has been touched.
I would like to get the index.

Does anybody how to do it?

Thanks in advance!!
The easiest way to do this would be to create a grid or row of UIButtons with their type set to custom, and install your UIImages from the array into each button. Set a tag on each button that corresponds to the array index. The view controller's viewDidLoad code could loop through using [[self view] viewWithTag: index] to finding each button and installing the images.

Then link all the buttons to the same IBAction that would use [sender tag] to get the index of the image that was tapped.

You could either set up your grid of buttons in IB in advance, or write code to lay them out.

If you don't use buttons, you could create a custom subclass of UIImageView that has userInteractionEnabled, and has a touchesBegan and/or touchesEnded method. Set each up with a delegate. The touch methods would generate a message to the delegate telling the delegate which image was touched. You'd need some logic in the view controller that would install the images into each custom image view.

Alternately you could create a custom subclass of UIView that would create a grid of UIImageView objects inside it, install the images from your array into those image views, and have that custom view handle touch events. It would have to do math on the coordinates of the touch to figure out which image was touched.

All of these approaches would be much easier if you lay out the images so each one takes up the same amount of space.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-18-2011, 08:02 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 70
juanchofern is on a distinguished road
Default

Thank you very much, i would try the first method.
Thanks again

Quote:
Originally Posted by Duncan C View Post
The easiest way to do this would be to create a grid or row of UIButtons with their type set to custom, and install your UIImages from the array into each button. Set a tag on each button that corresponds to the array index. The view controller's viewDidLoad code could loop through using [[self view] viewWithTag: index] to finding each button and installing the images.

Then link all the buttons to the same IBAction that would use [sender tag] to get the index of the image that was tapped.

You could either set up your grid of buttons in IB in advance, or write code to lay them out.

If you don't use buttons, you could create a custom subclass of UIImageView that has userInteractionEnabled, and has a touchesBegan and/or touchesEnded method. Set each up with a delegate. The touch methods would generate a message to the delegate telling the delegate which image was touched. You'd need some logic in the view controller that would install the images into each custom image view.

Alternately you could create a custom subclass of UIView that would create a grid of UIImageView objects inside it, install the images from your array into those image views, and have that custom view handle touch events. It would have to do math on the coordinates of the touch to figure out which image was touched.

All of these approaches would be much easier if you lay out the images so each one takes up the same amount of space.
juanchofern is offline   Reply With Quote
Reply

Bookmarks

Tags
detect, touch, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 392
14 members and 378 guests
7twenty7, chiataytuday, cristofercolmbos, dedeys78, fiftysixty, gmarro, iOS.Lover, jimmyon122, jonathandeknudt, pungs, raymng, stanny, tymex, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:09 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0