1

I want to use a class which extends from the NSObject class. This class will have a tree attribute. I want to assign values to these objects. So how to create a number of objects of that class and pass these objects as an array to picker?

Following are my three arrays. I want this in my class as the attribute

_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. "];

How to do this?

2
  • just use for loop , and assign values to that objects. Commented Feb 27, 2016 at 7:06
  • and how to pass this to picker sample code if any? Commented Feb 27, 2016 at 7:37

1 Answer 1

1
  1. Create custom Class with required properties.
  2. Create new mutable array say fruits
  3. In for loop, create custom class object and assign values to properties using array data you have described above. Add this custom object to new mutable array (here fruits). All objects will get added one by one in for loop
  4. Use this array as data source for picker. To fill picker values, you can access the properties of custom object in Fruit array

You can refer UIPickerView with NSDictionary

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.