1

我有一个TTStyledTextLabel里面的UITableViewCell。单击单元格导航到一个新的视图控制器,因此我无法禁用选择,但是当我单击 时TTStyledTextLabelUITableViewCell也选择了。在不选择表格视图单元格的情况下单击 TTStyledTextLabel 有什么想法吗?

4

1 回答 1

1

只需继承 TTStyledTextLabel并覆盖以下两个方法:

  • (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
  • (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event

像这样:

- (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];
        }
    }
}
于 2012-05-06T04:35:07.503 回答