?
Solved

UIIMageView ID ?

Posted on 2011-09-02
7
Medium Priority
?
530 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
Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

 
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 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

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I recently went through the process of creating an installable image of an iPhone mobile app (an .ipa file) that beta testers could load onto their test devices. The process involved quite a few steps, but both Appcelerator and Diawi.org had decent …
     Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON (https://github.com/SwiftyJSON/SwiftyJSON). If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

752 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