2012-01-14 5 views
5

에서 응용 프로그램 내 링크를 생성 내가 하나가를 NSTextView의 텍스트에서 링크를 만들 수 있습니다이 작은 조각을 발견 예를 들어 링크를 해석하고 해당 뷰/컨트롤러로 디스패치 할 수있는 특정 핸들러 클래스에?이를 NSTextView

답변

4

NSTextView 대리인의 링크 클릭 수는 특히 textView:clickedOnLink:atIndex: 메서드를 구현하여 처리 할 수 ​​있습니다. 당신이 때문 저장하는 경우

NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
          yourObject, @"YourCustomAttributeName", 
          @"link", NSLinkAttributeName, 
          nil]; 
NSAttributedString* string = [[[NSAttributedString alloc] initWithString:@"Your string" attributes:attributes] autorelease]; 

이 있는지 확인하십시오 : 당신이 각 링크 더 많은 정보를 저장해야하는 경우

, 당신은 링크가있는 문자열의 사용자 지정 속성으로 객체를 저장하여이 작업을 수행 할 수 있습니다 문자열이 use the NSCoding protocol이고 RTF 메서드가 NSAttributedString이 아니므로 RTF에서 사용자 지정 특성을 저장할 수 없습니다.