Нажатие на TTStyledTextLabel выбирает UITableViewCell

У меня есть TTStyledTextLabel внутри UITableViewCell, Нажав на ячейку, вы перейдете к новому контроллеру представления, поэтому я не могу отключить выбор, но когда я нажимаю TTStyledTextLabel, UITableViewCell также выбран. Любые мысли о нажатии TTStyledTextLabel без также выбора ячейки табличного представления?

1 ответ

Решение

Просто создайте подкласс TTStyledTextLabel и переопределите следующие два метода:

  • (void) touchesBegan: (NSSet *) касается события Event:(UIEvent*)
  • (void)touchesEnded:(NSSet*) касается события eventEvent:(UIEvent*)

именно так:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    UITouch* touch = [touches anyObject];
    CGPoint point = [touch locationInView:self];
    point.x -= _contentInset.left;
    point.y -= _contentInset.top;

    TTStyledBoxFrame* frame = [_text hitTest:point];
    if (frame) {
        [self setHighlightedFrame:frame];
    }
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
    TTTableView* tableView = (TTTableView*)[self ancestorOrSelfWithClass:[TTTableView class]];
    if (!tableView) {
        if (_highlightedNode) {
            // This is a dirty hack to decouple the UI from Style. TTOpenURL was originally within
            // the node implementation. One potential fix would be to provide some protocol for these
            // nodes to converse with.
            if ([_highlightedNode isKindOfClass:[TTStyledLinkNode class]]) {
                TTOpenURL([(TTStyledLinkNode*)_highlightedNode URL]);

            } else if ([_highlightedNode isKindOfClass:[TTStyledButtonNode class]]) {
                TTOpenURL([(TTStyledButtonNode*)_highlightedNode URL]);

            } else {
                [_highlightedNode performDefaultAction];
            }
            [self setHighlightedFrame:nil];
        }
    }
}
Другие вопросы по тегам