it doesn't seem possible to get the index of the clicked path item, nor does it seem possible to associate any kind of data with each path item,
What happens when you try this:
-(void)pathControlAction:(NSPathControl*)pathControl
{
NSPathControlItem *clickedPathItem = pathControl.clickedPathItem;
if (clickedPathItem == nil) { NSLog(@"whoops!"); return; }
NSUInteger index = [pathControl.pathItems indexOfObject:clickedPathItem];
if (index == NSNotFound) { NSLog(@"whoops!"); return; }
//do whatever.
}
They deprecated the cell based NSPathControl API without introducing proper replacements as you discovered. It's been so many years I get the feeling that they are never going to improve this so it's probably pretty safe to use the cell based stuff even though it's deprecated.
But if you don't want to do that your probably can associate data with path control items by subclassing and setting the path control items with some custom objects at the same time.
@interface MyPathControl : NSPathControl
//Each array must contain the same number of objects.
-(void)setPathControlItems:(NSArray<NSPathControlItem*>*)itemsArray
withRepresentedObjects:(NSArray<WhateverObject*>*)representedObjectsForEachItem;
-(void)setPathControlItems:(NSArray<NSPathControlItem*>*)itemsArray NS_UNAVAILABLE;
@end
Or something like that. Not great but that's all I can think of.
Topic:
UI Frameworks
SubTopic:
AppKit
Tags: