Solved

UIIMageView ID ?

Posted on 2011-09-02
7
519 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
  • 4
  • 3
7 Comments
 
LVL 19

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 19

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 19

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
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.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now