0

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.

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");
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
vinay
  • 1,276
  • 3
  • 20
  • 34

2 Answers2

2

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
  • 90,870
  • 19
  • 190
  • 224
  • Now i have edited the code.Now tell me answer.What i have to do for call the method in selector? – vinay Aug 09 '10 at 11:49
  • 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 Aug 09 '10 at 12:13
1

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

Zoe
  • 27,060
  • 21
  • 118
  • 148
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • Thanks for reply.If condition works and image also visible.But selector was not call the showRestaurant method.That was the issue.. – vinay Aug 09 '10 at 12:16