我想使用一个从 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. "];
如何做到这一点?
最佳答案
- 创建具有所需属性的自定义类。
- 创建新的可变数组 say fruits
- 在 for 循环中,创建自定义类对象并使用上面描述的数组数据为属性赋值。 将此自定义对象添加到新的可变数组(这里是水果)。所有的对象都会在for循环中一个一个的添加
- 使用这个数组作为选择器的数据源。要填充选择器值,您可以访问 Fruit 数组中自定义对象的属性
关于ios - 如何将对象分类为 Objective-C 中选择器的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35666780/