views:

30

answers:

1

I have a UIView subclass called Card that I move around on my board and drop on hot spots called slots. When I drop the card I use the hitTest to figure out if I am dropping the card on one of my hotspots. I want to get a property of that hot spot but I am having trouble getting that to work properly. My only guess is the hitTest returns a UIView and my hot spot is a UIView subclass. The error I get is "Request for member 'slotIndex' in something not a structure or union"

Here is the TouchesEnded method I am using from my Card Class

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event { 

   UITouch *touch = [touches anyObject];   
   CGPoint location = [touch locationInView:self.superview];

   [self setUserInteractionEnabled:NO];

   UIView *backView = [self.superview hitTest:location withEvent:nil];

   if ([backView isKindOfClass:[CardSlot class]]) {
      self.center = backView.center;

      NSLog(@"Slot Number: %@", backView.slotIndex);

   } else {
      //Move it back to the top corner
      self.center = CGPointMake(50,50);
   }

   [self setUserInteractionEnabled:YES];

}

My question is how do I go about testing if I am in a slot hot spot and then get the properties of that slot (UIView Subclass)?

A: 

To help the compiler, you need to cast the pointer to a CardSlot after determining that it is one. This way the compiler can know about the slotIndex property. For example:

if ([backView isKindOfClass:[CardSlot class]]) {
    CardSlot *cardSlot = (CardSlot *)backView;
    // From here you can access cardSlot.slotIndex
}
Sebastian Celis
Thanks for the quick and helpful reply.
SonnyBurnette