View Single Post
  #1 (permalink)  
Old April 24th, 2012, 10:42 PM
hughisheretoo hughisheretoo is offline
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Problem with ViewWithTag method in UIView

I have code below basically variation from the Concentration game. The code is the method that adds the cards(UiImageViews) to the view. That works as it does in the game. Except that at the bottom of the method I attempt to make changes to one of the views that I have added.

As part of the process of adding a subview I set the tag property. I looked in the apple docs and found a ViewWithTag method for the UIView class. I was hoping that I could use that method to select one of the subviews that I had added to the view and simply change the location of one of the cards.

In stepping through the code with debug. it apparently does not find the card that has the tag 5. The Tag and all of the x and y etc variables are all zero.

Is what I am trying logically correct. Or is there something wrong with my code. It would be a powerful function for my app if I had the capability of selection specific cards and being able to modify their properties.

thanks,
hugh
here is the code
Code:
-(void) addCardsInPlaceToView:(HO_Deck*) deck
{
    NSString *tCurrCardBase;
    CardImageView* card;
    CGRect cardFrame;
    CGRect cardOrigin = CGRectMake(0,0, 60, 80);
    
    cardFrame.size = CGSizeMake(60, 80);
    CGPoint origin;
    int x = 1;    
    NSTimeInterval timeDelay = 0.0;
    
    for (int i=0; i<4; i++) {
        for (int j=0; j<13; j++) {
            origin.y = i*80 + 110;
            origin.x = j * 60 + 150;
            cardFrame.origin = origin;
    
            // Create the card at the origin
            deck.currPtr = x;   
            tCurrCardBase = deck.currCardBase;
            
            // card = [[CardImageView alloc] initWithFrame:cardOrigin
            card = [[CardImageView alloc] initWithFrame:cardFrame 
                                               CardBase:tCurrCardBase
                                                 andTag:x];
            x +=1;
            
            // Configure gesture recognizer
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] 
                                           initWithTarget:self 
                                           action:@selector(handletap:)];
            tap.numberOfTapsRequired = 1;
            
            [card addGestureRecognizer:tap];
            
            // Configure gesture recognizer
            UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] 
                                           initWithTarget:self 
                                           action:@selector(handlePan:)];
            //pan.numberOfTapsRequired = 1;
            //[pan numberOfTouches1 ];
            
            [card addGestureRecognizer:pan]; 
            
            [self.view addSubview:card];
        }
        
    }
    // card = - (UIView *)viewWithTag:(NSInteger)tag
    NSInteger tCard5 = 5;
    UIView * DispCard;
        
    DispCard = [self.view viewWithTag:(tCard5)];
    NSInteger tTag = DispCard.tag;
    float tx = DispCard.frame.origin.x;
    float ty = DispCard.frame.origin.y;  
    float th = DispCard.frame.size.height;
    float tw = DispCard.frame.size.width;
    

}
Reply With Quote