Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top