I've created a custom UIView class FormDropdown, which contains a question & button in the nib. In the class is also an NSArray property which is supposed to store the various options for the button.
So a button can be placed by doing this, in for instance a viewDidLoad method:
FormDropdown *dropdown = [FormDropdown dropdownWithQuestion:@"This is an example question" andLabel:@"Select one" andOptions:[NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]];
[self.view addSubview:dropdown];
Obviously, I'd like the button to, when tapped, bring up a UIPickerView with the options showing. But I'm stuck on how to send the options to any method. I know I can attach an action to the button like so:
[dropdown.dropdownButton addTarget:self action:@selector(dropdownPressed:) forControlEvents:UIControlEventTouchUpInside];
..but I can't see how I would pass the options from the dropdown.options array to the method?
Inside the function, the integer value of the argument object is added to that on which the ‘add’ function is called. In this method, we can pass objects as an argument and alter them.
The idea of message passing is “ sending object will just send a message to one object and the other object will decide what to do ”.
Objects are a representation of real-world and objects communicate with each other via messages. When two or more objects communicate with each other that means that those objects are sending and receiving messages. This is often called method calling.
We can pass data to different components using parameters. If we add [Parameter] attribute to any public properties of a component, it becomes a parameter. If we add [Parameter] attribute to any public properties of a component, the property will become a parameter that can be passed to the component.
I believe that you can do this by adding an "associative reference" from the UIButton to your object data.
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocAssociativeReferences.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With