0

I have UIWebView for displaying articles. These are all HTML pages. I need to select text from articles. So, i'm using UIMenucontroller for select option. I need to select text while user tap on singleTap. But when use singleTap nothing happen.

-(void)ViewDidLoad{

UITapGestureRecognizer *singletapp=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
    singletapp.numberOfTapsRequired=1;

    [wbCont addGestureRecognizer:singletapp];

}

SingleTap:

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

     NSLog(@"single tap");

 CGPoint touchPoint = [gestureRecognizer locationInView:self.view];

 NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).toString()", touchPoint.x, touchPoint.y];

 NSString * tagName = [wbCont stringByEvaluatingJavaScriptFromString:js];

 NSLog(@"Selected Name: %@",tagName);

 }
user2807197
  • 207
  • 1
  • 4
  • 12

1 Answers1

0

Add this code in your viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(resetMenuController)
                                                     name:UIMenuControllerDidHideMenuNotification
                                                   object:nil];

Add this code in your class.Controller will not be shown

- (void) resetMenuController
{
    UIMenuItem *notesMI = [[UIMenuItem alloc] initWithTitle: @""
                                                     action: @selector(sample)];

    [[UIMenuController sharedMenuController] setMenuItems:@[notesMI]];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(sample))
    {
        return YES;
    }
    return NO;
}

- (void) sample{}
Desert Rose
  • 3,376
  • 1
  • 30
  • 36