call method from subclass of uiimageview

Discussion in 'iOS Programming' started by sregorcinimod, Apr 22, 2011.

  1. sregorcinimod, Apr 22, 2011
    Last edited by a moderator: Apr 22, 2011

    macrumors newbie

    Joined:
    Mar 8, 2011
    #1
    I have two .m files. The first is the main code, The second is a subclass of UIImageView so that i can detect touches.
    In the main .m file I have added a progress bar and a customimageview both subviews of a scrollview.

    What I need is that when a user touches the customimageview that the progress bar moves up and a double tap decreases the [Note: the customimageview has to have its touches recognised in the second .m because of them being in a subview of a scrollview and other controls are having to be handled]

    In the main .m file I have a two methods:

    Code:
        - (void)pumpsingletap {  
           progbm.progress +=0.1;  
        }  
      
        - (void)pumpdoubletap {  
           progbm.progress -=0.1;  
        }  
    
    then in the subclassed uiimageview i have:

    Code:
        //inside touches method
        if ([touch view].tag == 555) {  
           NSLog(@"pump touched");  
           switch ([allTouches count]) {  
                 case 1: {  
                        switch ([touch tapCount]) {  
                             //---single tap---  
                             case 1: {  
                             NSLog(@"single pump touch");  
                             [self performSelector:@selector(pumpsingletap) withObject:nil afterDelay:.4];  
                             } break;  
                             //---double tap---  
                             case 2: {  
                             NSLog(@"double pump touch");  
                             [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(pumpsingletap) object:nil];  
                             [self performSelector:@selector(pumpdoubletap) withObject:nil afterDelay:.4];  
                             } break;  
                       }  
                   }  
               }  
          }
    
    So the NSlog's appear so the touch recognition isn't an issue. But the performSelector falls over. As the customimageview pumpsingletap doesnt work.

    So how do i call the method in the subclass
     
  2. macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    I could be wrong here, but I believe for selector to work you have to at least declare an incoming object:

    Code:
    
    - (void)pumpdoubletap:(id) sender { 
    progbm.progress -=0.1; 
    } 
    
    
     
  3. thread starter macrumors newbie

    Joined:
    Mar 8, 2011
  4. sregorcinimod, Apr 22, 2011
    Last edited by a moderator: Apr 22, 2011

    thread starter macrumors newbie

    Joined:
    Mar 8, 2011
    #4
    method called but progress bar not moving

    o I have added in the following code, in my subclass

    Code:
        mainMethod* callingMethod = [[mainMethod alloc] init];  
        [callingMethod performSelector:@selector(pumpsingletap) withObject:nil afterDelay:.4];  
    
    then in my main method for pumpsingletap i changed it to:

    Code:
        - (void)pumpsingletap { 
           NSLog(@"single pump method called");
           progbm.progress +=0.1;  
        } 
    
    The NSLog for single pump method called appeared but the progress bar progbm - didn't move. so i have solved my calling issue - just need to now work out why the progress bar isnt moving!!
     

Share This Page