1

I have a NSBrowser that needs to display data that comes from a REST API. Sometimes this API takes a while to return results, so it would be nice to handle the network traffic in the background (lazy fetching). Sometimes a subtree needs to be refresh to reflect server side changes.

I've tried two different approaches:

  1. Using NSBrowserDelegate. When [browserDelegate browser:child:ofItem:] or similar function ends up requesting data that is not yet loaded, I return 0 count and kick off background processing. When the data becomes available I have the columns reloaded (not very efficient, messes with the user's selection as new data comes in).
  2. Using NSTreeController. I got this to work well using a blocking/synchronous approach. However, whenever I update the model, NSBrowser resets the tree and moves the selection up to the parent. I've tried [obj mutableArrayValueForKey] approach. I've tried the [treecontroller insertObject:atArrangedObjectIndexPath:] approach. I've toggled "preserve selections" flag. I've toggled "select on insert". No matter what I do, NSBrowser doesn't want to cleanly update only the relevant subtree.

Bottom line: what is the best practice for asynchronously loading data into an NSBrowser?

korch458
  • 13
  • 3
  • Hello. Did you find a satisfiying approach? I'm going to implement a similar component.. – hariseldon78 Jul 07 '14 at 15:55
  • 1
    The bindings approach involved too much unknown "magic" behind the scenes. The NSBrowserDelegate approach turned out to be the least problematic. A reasonable compromise was to display a temporary "Loading..." item in the column, then reload the column with valid entries. – korch458 Jul 07 '14 at 20:01

0 Answers0