Question

I have added a label with some text and links to an ScrollView, when you tap on those links (in the label), a delegate method will call, displays a popover and show some related information.

but problem starts from here, I want when you tap on anywhere else except the links, the popover disappear.

if I add a UITapGestureRecognizer to ScrollView, the delegate method for links won't call.

what should I do to label handles the tap on links, and ScrollView Handles the other taps?

I did like that:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
    [self.scrollView addGestureRecognizer:tap];

- (void)tapped
{
    if ([self.storyText.delegate respondsToSelector:@selector(attributedLabel:shouldFollowLink:)])

        [self.storyText.delegate performSelector:@selector(attributedLabel:shouldFollowLink:) withObject:self.storyText];
}

In tapped method Im checking if Im tapping on a link, the delegate should be called, but Delegate wont call. Am I missing someThing?

enter image description here

Was it helpful?

Solution 2

Solved! Solution: first I create a custom class for my scrollView and subclassed that from UIScrollView. Second I override

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

in my custom ScrollView class. in this method I called a method to dismiss the popover.

but important part is that in viewWillAppear method of the class which popover will appear, I passed self to custom scrollView class. because if I didn't that, the method for dismissing popover won't work (it needs an object of this class).

[self.scrollView initWithStoryViewController:self];

enter image description here

this images show in which scenario I had this problem:

OTHER TIPS

You can use custom UIButtons instead of labels or you can place custom UIButtons with clear background color over the links and give actions to this buttons.

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