tags:

views:

123

answers:

2

I have placed the uiscrollview for viewcontroller.Then i have set my large size image as imageView in to the uiscrollView.Then i have set the some buttons into the imageView.In that imageview, i have called one method "showRestaurant".But the selector failed to called the method.Kindly help me regarding on this.Thanks in advance.

Code:

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {

    float newScale = [imageScrollView zoomScale] * ZOOM_STEP;
    CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];        

    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"restaurant.png"] forState:UIControlStateNormal];
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"restaurant.png"] forState:UIControlStateNormal];

    [imageScrollView zoomToRect:zoomRect animated:YES];

    if(newScale==1.500){        
        btn1.frame = CGRectMake(2370.828125,1020.015625,35,34);         
        [btn1 addTarget:self action:@selector(showRestaurant) forControlEvents:UIControlEventTouchUpInside];
        [imageView addSubview:btn1];

        btn2.frame = CGRectMake(2270.828125,1070.015625,35,34);     
        [btn2 addTarget:self action:@selector(showRestaurant) forControlEvents:UIControlEventTouchUpInside];
        [imageView addSubview:btn2];
    }
}

-(void)showRestaurant{
    NSLog(@"testing321");
}
+1  A: 

Does the program flow even go inside the "if" ? That comparisons seem very weird (why do you convert floats to strings and then compare strings). Add a debug output inside your "if" to check whether you really end up in that block. Also, btn1 has the imageScrollView as target, btn2 has "self" as target. That also doesn't look right.

DarkDust
Now i have edited the code.Now tell me answer.What i have to do for call the method in selector?
vinay
So, do the buttons appear ? If no, then the "if" is not entered. If yes, and touching a button doesn't bring the "testing321" message, then there might be an issue with setting up the UIScrollView (like in http://stackoverflow.com/questions/650437/iphone-uiscrollview-with-uibuttons-how-to-recreate-springboard). So it might help to post the code you use for setting up your "imageScrollView" variable.
DarkDust
+1  A: 

Please verify, that your if-clause get entered. Checking equality on float values is problematic, as the might be rounded to 1.500000000001 or 1.49999999999 or something similar.

try if(newScale>1.49) instead

BTW:

Now tell me answer

sounds quite rude to me

vikingosegundo
Thanks for reply.If condition works and image also visible.But selector was not call the showRestaurant method.That was the issue..
vinay