Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. - (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)_tokens atIndex:(NSUInteger)index
  2. - (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject
  3. - (NSTokenStyle)tokenField:(NSTokenField *)tokenField styleForRepresentedObject:(id)representedObject
  4. - (BOOL)tokenField:(NSTokenField *)tokenField hasMenuForRepresentedObject:(id)representedObject
  5. - (NSMenu *)tokenField:(NSTokenField *)tokenField menuForRepresentedObject:(id)representedObject
  6. - (BOOL)tokenField:(NSTokenField *)tokenField writeRepresentedObjects:(NSArray *)objects toPasteboard:(NSPasteboard *)pboard
  7. - (NSArray *)tokenField:(NSTokenField *)tokenField readFromPasteboard:(NSPasteboard *)pboard
  8.  
  9. NSArray *objects = [self.tokenField objectValue];
  10. NSTextView *tv = [[self.tokenField cell] fieldEditorForView:self.tokenField];
  11. NSArray *selections =[tv selectedRanges];
  12.  
  13. for (NSValue *rangeVal in selections) {
  14. NSRange range = [rangeVal rangeValue];
  15. for (NSUInteger i=0; i<range.length; i++) {
  16. NSLog(@"%@", [objects objectAtIndex:range.location + i]);
  17. }
  18. }
  19.  
  20. public func textViewDidChangeSelection(notification: NSNotification) {
  21.  
  22. if let fieldView = tokenField.cell!.fieldEditorForView(self) {
  23.  
  24. var selectedObjects = [AnyObject]()
  25.  
  26. for value in fieldView.selectedRanges {
  27. let range = value.rangeValue
  28.  
  29. for var i = 0 ; i < range.length ; i++ {
  30. selectedObjects.append(tokenField.objectValue!.objectAtIndex(range.location + i))
  31. }
  32. }
  33. Swift.print("selected objects:(selectedObjects)")
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement