0

I know that when the error is "'blah' was not declared in this scope" means when the object was not created correctly, but when I am making a Notification Center widget for iOS, using the WeeLoader template and THEOS to compile, I am getting this error: 'UITapGestureRecognizer' was not declared in this scope.

Here is my .mm file:

- (void)loadFullView {
     UITapGestureRecognizer *Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];


     UIImage *bg = [[UIImage imageWithContentsOfFile:@"/System/Library/WeeAppPlugins/WeeAppTest.bundle/WeeAppBackground.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:71];
     UIImageView *bgView = [[UIImageView alloc] initWithImage:bg];
     bgView.frame = CGRectMake(0, 0, 316, 71);     
     bgView.userInteractionEnabled = YES;

     [bgView addGestureRecognizer:Tap];

     [_view addSubview:bgView];
     [bgView release];
     [Tap release];

      UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 316, 71)];
      lbl.backgroundColor = [UIColor clearColor];
      lbl.textColor = [UIColor whiteColor];
      lbl.text = @"Hello world";
      lbl.textAlignment = UITextAlignmentCenter;
      [_view addSubview:lbl];
      [lbl release];
}

-(void) handleTapGesture:(UIGestureRecognizer *) sender {

}

What am I doing wrong? I am pretty sure that I am declaring everything correctly, by the way, the code does work with out the UITapGestureRecognizer.

Thank you.

Matthew S.
  • 711
  • 1
  • 5
  • 22

1 Answers1

1

I think there are a few things going on here.

I think you could be getting the out of scope error because the gesture recognizer should be declared in the viewDidLoad or the init methods.

Also, in the UITapGestureRecognizer *Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; You call your method handleSingleTap:

Therefore your method should be -(void) handleSingleTap:(UITapGestureRecognizer *) sender

badger0053
  • 1,179
  • 1
  • 13
  • 19
  • Thank you for response, I had tried creating the `UITapGestureRecognizer` in the init, viewdidload, and also trying to create it in the interface. Still the same error :(. Also the method name was an typo in writing the question, sorry about that. – Matthew S. Mar 04 '13 at 01:14
  • @RandomAwesomeGuy Can you post more of your code? This worked for me. http://pastebin.com/VuH4Gk8G – badger0053 Mar 04 '13 at 01:30
  • @RandomAwesomeGuy I believe the problem is that your class is of type `NSObject` you should be creating gesture recognizer in a `UIViewController` Class – badger0053 Mar 04 '13 at 02:31
  • Thank you very much, I will try that, that never crossed my mind :P – Matthew S. Mar 04 '13 at 05:16