KILabel icon indicating copy to clipboard operation
KILabel copied to clipboard

KILabel lead to a wrong index for didSelectRowAtIndexPath

Open zzyhappyzzy opened this issue 10 years ago • 2 comments

lead a wrong index when select between cells。 KILabel which on a tableviewCell contentView lead to a wrong index for didSelectRowAtIndexPath

zzyhappyzzy avatar Jan 21 '16 04:01 zzyhappyzzy

It was already explained in other ticket. There is a typo in touchesEnded:withEvent method.

You need to replace line 686: [super touchesBegan:touches withEvent:event];

with: [super touchesEnded:touches withEvent:event];

I have also moved [super touchesEnded:touches withEvent:event]; call from line 661 to line 667.

The final touchesEnded:withEvent method should look like this:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    // If the user dragged their finger we ignore the touch
    if (_isTouchMoved)
    {
        self.selectedRange = NSMakeRange(0, 0);
        [super touchesEnded:touches withEvent:event];
        return;
    }

    // Get the info for the touched link if there is one
    NSDictionary *touchedLink;
    CGPoint touchLocation = [[touches anyObject] locationInView:self];
    touchedLink = [self linkAtPoint:touchLocation];

    if (touchedLink)
    {
        NSRange range = [[touchedLink objectForKey:KILabelRangeKey] rangeValue];
        NSString *touchedSubstring = [touchedLink objectForKey:KILabelLinkKey];
        KILinkType linkType = (KILinkType)[[touchedLink objectForKey:KILabelLinkTypeKey] intValue];

        [self receivedActionForLinkType:linkType string:touchedSubstring range:range];
    }
    else
    {
        [super touchesEnded:touches withEvent:event];
    }

    self.selectedRange = NSMakeRange(0, 0);
}

Guferos avatar Jan 21 '16 13:01 Guferos

Thanks for your reply ! Best Regards !

在 2016年1月21日,下午9:42,Damian Wojtczak [email protected] 写道:

It was already explained in other ticket. There is a typo in touchesEnded:withEvent method.

You need to replace line 686: [super touchesBegan:touches withEvent:event];

with: [super touchesEnded:touches withEvent:event];

I have also moved [super touchesEnded:touches withEvent:event]; call from line 667 to line 667.

The final touchesEnded:withEvent method should look like this:

  • (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // If the user dragged their finger we ignore the touch if (_isTouchMoved) { self.selectedRange = NSMakeRange(0, 0); [super touchesEnded:touches withEvent:event]; return; }

    // Get the info for the touched link if there is one NSDictionary *touchedLink; CGPoint touchLocation = [[touches anyObject] locationInView:self]; touchedLink = [self linkAtPoint:touchLocation];

    if (touchedLink) { NSRange range = [[touchedLink objectForKey:KILabelRangeKey] rangeValue]; NSString *touchedSubstring = [touchedLink objectForKey:KILabelLinkKey]; KILinkType linkType = (KILinkType)[[touchedLink objectForKey:KILabelLinkTypeKey] intValue];

    [self receivedActionForLinkType:linkType string:touchedSubstring range:range];
    

    } else { [super touchesEnded:touches withEvent:event]; }

    self.selectedRange = NSMakeRange(0, 0); } — Reply to this email directly or view it on GitHub https://github.com/Krelborn/KILabel/issues/57#issuecomment-173573262.

zzyhappyzzy avatar Jan 22 '16 02:01 zzyhappyzzy