Post

Replies

Boosts

Views

Activity

Reply to Getting clicked item index in NSPathControl with pathItems instead of pathComponentCells
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:
Feb ’23
Reply to Getting clicked item index in NSPathControl with pathItems instead of pathComponentCells
That's the incredible thing: sender.pathItems.firstIndex(of: sender.clickedPathItem!) always returns nil, even if the clicked path item has the same address as the corresponding item in the path items array. Even sender.pathItems.firstIndex(where: { $0.description == sender.clickedPathItem!.description }) returns nil. And when executing that print statement more than once one after the other, each item always has a different address. Not sure. I don't have time to test this thoroughly but try overriding the pathControlItems setter to see if you or the system are resetting the array unexpectedly. How are you creating each NSPathControlItem? In any case as long as each NSPathControlItem URL is unique you can just hold whatever data you want to associate with each path item like so: @property NSDictionary<NSURL*,Whatever*>*representedObjectsForPathURLs; Then add a method on your path control subclass: -(Whatever*)representedObjectForPathControlItem:(NSPathControlItem*)item { return [self.representedObjectsForPathURLs objectForKey:item.URL]; } This assumes NSPathControlItem doesn't mangle your url strings after they are set.
Topic: UI Frameworks SubTopic: AppKit Tags:
Feb ’23
Reply to Getting clicked item index in NSPathControl with pathItems instead of pathComponentCells
Take out your PathControlItem subclass. Add a property on PathControl that maps the the path control item titles to your custom data (assuming each path control item has a unique title). Just change the code from my previous response to use the title as the dictionary key instead of NSURL if you aren't setting a URL. //Add this to PathControl. @interface PathControl : NSPathControl //Set this. @property NSDictionary<NSString*,Whatever*>*representedObjectsForPathItemTitles; -(Whatever*)representedObjectForPathControlItem:(NSPathControlItem*)item; @end @implementation PathControl -(Whatever*)representedObjectForPathControlItem:(NSPathControlItem*)item { return [self.representedObjectsForPathItemTitles objectForKey:item.title]; } Unless your titles aren't unique, in which case you'd have to figure out another way to do this.
Topic: UI Frameworks SubTopic: AppKit Tags:
Feb ’23
Reply to WKWebView Loading HTML Strings Taking An Extremely Long Time On Mac Catalyst (Ventura 13.2.1)
Just to add, I make the call to -loadHTMLString:baseURL: in -viewWIllAppear:. I use a BOOL to make sure I only call -loadHTMLString:baseURL: once since viewWillAppear: can be called multiple times. This is how my code has always been. What's weird is if I move the -loadHTMLString:baseURL: call to -viewDidAppear: loading appears to be a bit faster (not as fast as it should be though, but better) even though -viewDidAppear is called after viewWillAppear. Is it just in my head or is WKWebView trying to optimize and it's actually throttling/delaying the page load? If so it seems to be trying too hard to optimize the window is visible and active and I see my spinner for way too long. Is it waiting for some window state to finish "loading' and draw on screen?
Topic: Safari & Web SubTopic: General Tags:
Feb ’23
Reply to Mac Catalyst: UITableView Suddenly Randomly Selecting Rows After Deleting Row Via Swipe Action After a Bit of A Delay
Okay so I have two window scenes open (windows) and the auto selecting was happening in one window and not the other. I figured out how to trigger it: UITableView just starts doing this after I move the selection with the arrow keys shortly before doing a swipe delete. The focus system just acts bizarre. I really didn't need to run into another one of these UITableView bugs... errr.. I'll see if I can come up with something to prevent it tomorrow. Anyone else got anything on this?
Topic: UI Frameworks SubTopic: UIKit Tags:
Feb ’23
Reply to Mac Catalyst: UITableView Suddenly Randomly Selecting Rows After Deleting Row Via Swipe Action After a Bit of A Delay
So I attempted to workaround the issue by disabling table view focus just before doing the swipe delete action...then enabling it again after a bit of a delay in -tableView:didEndEditingRowAtIndexPath: And that avoids the auto selecting, assuming I do it after a long enough delay since the focus system must be queuing all this up on timers. But if you click outside the window, then reactivate the window, the focus system just selects the first row automatically in the table view after focus is reenabled. I could suppress it by returning NO from -tableView:shouldHighlightRowAtIndexPath: or canFocusOnItemAtIndexPath: but there is no good way to determine when I should suppress the selection to workaround this issue. Anyone know a way to tame the focus system? Can I clear its queue? A method like -cancelQueuedFocusSystemUpdateRequestsTakeItEasyPlease ?
Topic: UI Frameworks SubTopic: UIKit Tags:
Feb ’23