ios - 如何将对象分类为 Objective-C 中选择器的数组

标签 ios picker

我想使用一个从 NSObject 类扩展而来的类。这个类将有一个树属性。我想为这些对象赋值。那么如何创建该类的多个对象并将这些对象作为数组传递给选择器呢?

以下是我的三个数组。我希望在我的类(class)中将其作为属性

_arrayImg=@[@"apple.jpg",@"banana.jpg",@"grapes.jpg",@"strawberry.jpg",@"watermelon.jpg"];

_arrayName=@[@"apple",@"banana",@"grapes",@"strawberry",@"watermelon"];

_arrayDesc=@[@"Apple is contain the vitamin A. Apple comes from kasmir.",@"Banana is very healthy. Banana contain more calaris than any other fruit. ",@"Grapes are mostly use to make the wine and grapes are having two types green and black.",@"strawberry is the sweet fruit and mostly comes in the cold environment.",@"watermelon is fruit which does not have the trees like other fruits. They  are having the climber. "];

如何做到这一点?

最佳答案

  1. 创建具有所需属性的自定义类。
  2. 创建新的可变数组 say fruits
  3. 在 for 循环中,创建自定义类对象并使用上面描述的数组数据为属性赋值。 将此自定义对象添加到新的可变数组(这里是水果)。所有的对象都会在for循环中一个一个的添加
  4. 使用这个数组作为选择器的数据源。要填充选择器值,您可以访问 Fruit 数组中自定义对象的属性

可以引用UIPickerView with NSDictionary

关于ios - 如何将对象分类为 Objective-C 中选择器的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35666780/

相关文章:

ios - 使用一个 Storyboard和一个 Storyboard将 iPad 应用程序移植到 iPhone

ios - 在 SwiftUI 中,我如何知道 Picker 选择何时更改?为什么 didSet 不起作用?

ios - 在 Photoshop 中设计 iphone 应用程序要设置什么分辨率?

iphone - 从现有网站制作移动应用程序

python - 导入错误 :cannot import name get_model

ios - 来自 JSON 的 SwiftUI Picker 数据未显示

iOS7:触摸按钮弹出选择器(背景模糊)

android - 具有自定义值的数字选择器在点击时显示错误数据

android - 在 ionic 2 中使用 SQLite 时出现 sqlitePlugin 错误

ios - 为 dequeueReusableCellWithIdentifier 使用变量