首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单击某个TTStyledTextLabel将选择该UITableViewCell

单击某个TTStyledTextLabel将选择该UITableViewCell
EN

Stack Overflow用户
提问于 2012-05-04 02:13:37
回答 1查看 228关注 0票数 1

我在UITableViewCell中有一个TTStyledTextLabel。单击单元格会导航到一个新的视图控制器,所以我不能禁用选择,但是当我单击TTStyledTextLabel时,UITableViewCell也会被选中。在不选择表视图单元的情况下单击TTStyledTextLabel有什么想法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-06 12:35:08

只需将TTStyledTextLabel子类化并覆盖以下两个方法:

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

就像这样:

代码语言:javascript
复制
- (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];
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10437068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档