Solved

UIIMageView ID ?

Posted on 2011-09-02
7
528 Views
Last Modified: 2012-05-12
Hello EE,

I was wondering if it was possible in XCode to put a tag or an ID to an UI Image view? My main concern is that once a user has touch the image I would to do something. But how can I know that he touches picture No. 3? or 2... or 6?

If it was possible to have an ID or tag or something so I can place the pictureID that comes from my database I could do anything I want...

any idea?
0
Comment
Question by:PhilippeRenaud
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 20

Expert Comment

by:darbid73
ID: 36476947
All views in iOS have a tag property.

See here for the tag property..
Apple Reference for UIView

When I need to do what you want to do I either set the tag property in Interface builder or when creating the view with

imageView.tag = 101;

Open in new window


Then somewhere at the top I have this

#define pic1 101

Now when I want to check what has been touched I use a test like this...

imageView.tag = pic1

Open in new window

0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 36478049
ok thanks.

but what if the ID or the value is a String?  tag i think is only integeR?
0
 
LVL 20

Expert Comment

by:darbid73
ID: 36478491
the id cannot be a string, thus the reason why I define it as a string to make more sense.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 36478724
Alright for the Tag.

But one last thing, do you have an example on how you retrieve the tag on when you touch the image?

even if the tag is set, im confused on how I get the info on when the user touches the image he wants..
0
 
LVL 20

Accepted Solution

by:
darbid73 earned 500 total points
ID: 36478771
That really would be better done in a new question..... but here.  If you have problems open a new question and let me know.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	
	UITouch *touch = [touches anyObject];
    //you can see the view or its tag that was touched.
    NSLog(@"Touch View %@", [touch view]);

	
}

Open in new window

0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 36480426
Yes sorry should had done a new question.
0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
ID: 36480427
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What's a UDID? If you're involved in developing, testing, or even reviewing an iOS application that's in beta, then at some point you may need to know the UDID for any iOS devices that you'll be testing on. What's the UDID? It stands for Unique Dev…
How to take pictures with depth using iOS 10
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question