从XML文件中动态加载NSPopUpButton内容

时间:2023-02-06 13:17:08

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

如何使用XML文件动态填充NSPopUpButton的内容值?我需要使用数组,对吗?

Please, please provide example code.

请提供示例代码。

1 个解决方案

#1


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:

你没必要,虽然它会让事情变得更容易。您需要从XML文件中提取数据;看一下NSXMLDocument文档,以及它的超类NSXMLNode的文档;这些类使得从XML中检索不同的“节点”变得相当容易,并将它们放入数组中。从那里,可以轻松检索其字符串值,将此信息添加到NSPopupButton实例:

[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.

其中objects是一个NSArray(或NSMutableArray),其中包含要添加到弹出按钮的项的标题,popUpButton是指向NSPopUpButton实例的指针。

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

本文还应该为您提供有关使用XML数据和从中检索数据的更多信息。

#1


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:

你没必要,虽然它会让事情变得更容易。您需要从XML文件中提取数据;看一下NSXMLDocument文档,以及它的超类NSXMLNode的文档;这些类使得从XML中检索不同的“节点”变得相当容易,并将它们放入数组中。从那里,可以轻松检索其字符串值,将此信息添加到NSPopupButton实例:

[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.

其中objects是一个NSArray(或NSMutableArray),其中包含要添加到弹出按钮的项的标题,popUpButton是指向NSPopUpButton实例的指针。

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

本文还应该为您提供有关使用XML数据和从中检索数据的更多信息。