Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sregorcinimod

macrumors newbie
Original poster
Mar 8, 2011
12
0
I have created a subclass of UIView in order to handle hitTest and Touches actions, as the UIView is a subview of a UIScrollview and I needed both the UIView and UIScrollView to be draggable.

I have got it 95% working - the subclassed UIView works perfectly if I jsut set a background colour - but if I set a subview with an image with transparanecy it doesn't always respond. I have some ideas on this so thats not the question.

My question is that as I have multiple instances of the subclassed UIView on the UIScrollview, how can i tell which one is dragged.

In a previous app I simply used;
if ([touch view] == blah) {
do something;
}
else if ([touch view] == fred) {
do nothing;
}
but as this sits in my main application .m file this was ok as blah and fred were both created there in viewdidload, but as the touch events in my code are captured in the subclass they don't know about blah and fred.

so 1) how do i let the subclass know about the items i've added - or -
2) how do i pass the name of the item through to the subclass in either hitTest or TouchesBegan - or -
3) is there a line of code to get the name of the current item

Any help much appreciated.
 
Problem Solved

So for anyone else who also has the same problem.

I found a simple solution:

In my viewDidLoad when I added the subclassed subviews, I just add in the line customView1.tag = 111;

then in the subclass within my touches methods I can just use:
if ([touch view].tag == 111) {

Simple! :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.