Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more


UIIMageView ID ?

Posted on 2011-09-02
Medium Priority
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?
Question by:PhilippeRenaud
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
LVL 20

Expert Comment

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


Author Comment

ID: 36478049
ok thanks.

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

Expert Comment

ID: 36478491
the id cannot be a string, thus the reason why I define it as a string to make more sense.
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.


Author Comment

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..
LVL 20

Accepted Solution

darbid73 earned 2000 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


Author Comment

ID: 36480426
Yes sorry should had done a new question.

Author Closing Comment

ID: 36480427

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

In this article I'm going to cover the basics and usages of NSInvocation. What is NSInvocation? Apple Developer Reference describes NSInvocation this way: An NSInvocation is an Objective-C message rendered static, that is, it is an action tur…
The Basics of Storyboard Storyboards were first introduced to developers in the release of iOS 5. They save the developer the trouble of designing each screen’s interface in a different file. The storyboard allows you to see the conceptual mockup o…
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
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

647 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