2012-05-03 5 views
1

UITableViewCell 안에 TTStyledTextLabel이 있습니다. 셀을 클릭하면 새보기 컨트롤러로 이동하므로 선택을 비활성화 할 수 없지만 TTStyledTextLabel을 클릭하면 UITableViewCell도 선택됩니다. 테이블보기 셀을 선택하지 않고 TTStyledTextLabel을 클릭하면 어떤 생각을 할 수 있습니까?TTStyledTextLabel을 클릭하면 UITableViewCell이 선택됩니다.

답변

1

그냥 서브 클래스 TTStyledTextLabel 다음과 같은 두 가지 방법을 오버라이드 (override) :

  • (무효) touchesBegan : (NSSet *)는 withEvent 접촉 : (UIEvent를 *) 이벤트
  • (무효)가 touchesEnded : (NSSet * (의 UIEvent *) 이벤트 바로이 같은

:)는 withEvent 접촉

- (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]; 
     } 
    } 
} 
+0

감사합니다. 몇 가지 변경 사항이 있었지만 링크를 통해 터치 만 차단할 수있었습니다. –

관련 문제