2010-08-30 71 views
0

我有一個名爲卡的UIView子類,我在我的主板上移動並放在熱點稱爲插槽。當我放下卡時,我使用hitTest來確定是否將卡放在我的熱點之一。我想獲得該熱點的財產,但我無法正常工作。我唯一的猜測是hitTest返回一個UIView,而我的熱點是一個UIView子類。我得到的錯誤是「請求成員的slotIndex'的東西不是一個結構或聯合」幫助Subclass屬性

這裏是TouchesEnded方法,我從我的卡類使用

-(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]; 

} 

我的問題是我怎麼去關於測試我是否在插槽熱點,然後獲取該插槽的屬性(UIView子類)?

回答

0

爲了幫助編譯器,您需要在確定它爲一個之後將指針轉到CardSlot。這樣編譯器就可以知道slotIndex屬性。例如:

if ([backView isKindOfClass:[CardSlot class]]) { 
    CardSlot *cardSlot = (CardSlot *)backView; 
    // From here you can access cardSlot.slotIndex 
} 
+0

感謝您的快速和有益的答覆。 – SonnyBurnette 2010-08-30 14:43:05