2009-05-12 4 views
2

창에 NSTableView 및 NSTokenField가 있습니다. 나는 다음과 같은 위임 메서드를 구현 :개체 컨테이너에서 토큰으로 NSTokenField 채우기

tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: 
tokenField:representedObjectForEditingString: 
tokenField:displayStringForRepresentedObject: 

은 내가 행이 선택 될 때 NSTokenField은 행 개체의 NSMutableSet에 포함 된 태그로 채워 가도록 (듯이)을 만들고 싶어. NSTokenField가 표현하는 객체의 컨테이너가 있으면 토큰을 채우는 방법 (따라서 토큰으로 만들어야하는 문자열)은 어떻게됩니까?

답변

4

나는 그것을 알아 냈다. 아래의 코드에서 내 개체를 포함하는 NSMutableSet입니다. [tokenField setObjectValue : MA]

 //set the token field 
     NSMutableArray *ma = [[NSMutableArray alloc] init]; 
     for (MyClass *anObject in ms){ 
      [ma addObject:anObject]; 
     } 

     //sort the array 
     NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey: @"title" ascending: YES]; 
     NSArray *sortDescriptorArray = [[NSArray alloc] initWithObjects:sorter, nil]; 

     [ma sortUsingDescriptors:sortDescriptorArray]; 
     [tokenField setObjectValue:ma]; 

키는 마지막 라인이고;

관련 문제