views:

128

answers:

1

How do I populate the content values of a NSPopUpButton dynamically using a XML file? I need to use arrays, right?

Please, please provide example code.

+1  A: 

You don't have to, although it would make things easier. You need to extract the data from your XML file; take a look at the NSXMLDocument documentation, and the documentation for its superclass, NSXMLNode; these classes make it fairly easy to retrieve different "nodes" from your XML, and place them into an array. From there, it is easy to retrieve their string values, add this information to your NSPopupButton instance:

[popUpButton addItemsWithTitles:objects];

Where objects is an NSArray (or NSMutableArray) containing the titles of the items you want to add to the pop up button, and popUpButton is the pointer to your NSPopUpButton instance.

This article should also provide you with some more information about working with XML data and retrieving data from it.

Perspx