views:

398

answers:

4

There are multiple ways to fill an NSTableView up with data through either bindings, delegates, or data sources.

What is the best way to go about filling up the tableview with data that is changed pretty frequently from an XML-RPC server? I'm targeting Mac OS X 10.5 only and there are lots of examples on how to do it, but nothing very definitive.

Any opinions?

+1  A: 

If I'm understanding correctly, it's really two separate questions. How do I fetch XML-RPC data, and how to populate a tableview?

I'm not too familiar with XML-RPC, but from doing a quick look around it seems like you can either do the parsing yourself with the NSXML* classes, or use one of several third party frameworks. I think it would be a good idea to look at the available frameworks first, even if you don't end up using one they should give you a good idea of how to go about parsing the XML data yourself if you go that route.

Once you have your data from the XML-RPC request, you'll want to store that in some sort of data structure in a controller class. You could use an array of dictionaries or basic strings, or make a custom object to represent your data, but that really depends on the complexity of what you're doing. The controller object will provide data to the table view, handle refreshing, and any other tasks you may need to do. You could make the XML-RPC request directly from the controller, or you may wish to create an additional class for this to separate the code.

Whether you use data source methods or bindings (along with an array controller) doesn't really matter, they both work fine and have their own advantages. If you're just starting with Cocoa, definitely use data source methods. Bindings requires intermediate knowledge of Objective-C and Cocoa, and will be hard to use and debug otherwise.

Marc Charbonneau
A: 

I don't know what the best way is. I don't really think there's a good way, so the "best way" is really going to be "the least worse" way.

Take a look at Web Services Core. It's a Carbon API for interacting with XML-RPC and SOAP web services. I've only used the SOAP functionality, but the XML-RPC should work as well. It's painful because it's Carbon and not Cocoa; but there's a lot of networking code you won't have to write which should be a win.

After that, I would wrap up all of the stuff talking to WSCore into a single class and make it implement the NSTableViewDataSource protocol and just point your table view at it as the table's data source. Every time the data from the web service changes, just call reloadData to get the table view to refresh itself.

Good luck. Web service support on OS X is painful at best, so you're going to need it.

James Williams
Thanks for your suggestions and wishes for best luck.
A: 

I would use data source because it's very simple and flexible. Your object that provides the data to NSTableView only needs to implement 2 functions:

  1. return number of rows
  2. return an object for a given row/column

How the object stores the data internally is totally up to you (flexibility) so you can choose whatever matches best how you parse the xml-rpc response.

More about NSTableViewDataSource

Krzysztof Kowalczyk
A: 

I found this xmlrpc framework much easier to use. You will of course still need to do the wrapping as explained before as these are really two different questions/problems.

tcurdt