我在TTStyledTextLabel
中有一个UITableViewCell
。单击单元格会导航到新的视图控制器,因此我无法禁用选择,但是当我单击TTStyledTextLabel
时,也会选择UITableViewCell
。在不选择表视图单元的情况下单击TTStyledTextLabel有什么想法吗?
最佳答案
仅将TTStyledTextLabel子类化,并覆盖以下两个方法:
(void)touchesBegan:(NSSet *)touch withEvent:(UIEvent *)事件
(void)touchesEnded:(NSSet *)touch withEvent:(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];
}
}
}
关于iphone - 单击TTStyledTextLabel选择UITableViewCell,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10437068/