我TTStyledTextLabel
内有UITableViewCell
。单击单元格导航到新的视图控制器,因此我无法禁用选择,但是当我单击TTStyledTextLabel
时,也会选择UITableViewCell
。有关单击TTStyledTextLabel而不选择表格视图单元格的想法吗?
答案 0 :(得分:1)
只是继承 TTStyledTextLabel 并重写以下两种方法:
就像这样:
- (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];
}
}
}